$(document).ready(function() {

//$('.rounded').corner("8px");

//$("body").supersleight();

$("body").append('<div id="AXBussy"><p><img src="/inc/gfx/ajax-loader.gif" /></p></div>');
$("#AXBussy").css({
		display:"none",
		margin:"0px",
		paddingLeft:"0px",
		paddingRight:"0px",
		paddingTop:"0px",
		paddingBottom:"0px",
		position:"absolute",
		right:"3px",
		top:"3px",
		width:"auto"
	});
// Ajax activity indicator bound 
// to ajax start/stop document events
$(document)
	.ajaxStart(function(){
			axto=setTimeout ( function() {$('#AXBussy').show();}, 500); 		
//			$("body").css("cursor","progress");
//			$(":button").css("cursor","progress");
//			$("a").css("cursor","progress");
						})
	.ajaxStop(function(){ 
			$('#AXBussy').stop(true).hide();
			clearTimeout(axto);		   
//			$("body").css("cursor", "auto");
//			$(":button").css("cursor", "pointer");
//			$("a").css("cursor", "auto");
//			$("input:disabled").css("cursor","default");
});

$('#hosting_home').mouseover(function(){
						$(this).css("cursor","pointer");				  
						$('#hosting_opis').css("background-position","top left");
					})
					.mouseenter(function(){	
						$('#ht_home').pulse({ speed: 400, textColors: ['#bbbbbb','#ffffcc']});
						$('#hosting_opis_inner span').hide();
						$('#hoi_home').show();
					})
					.mouseleave(function(){	
						$('#ht_home').recover(); // stops pulse
					});
$('#hosting_business').mouseover(function(){
						$(this).css("cursor","pointer");				  
						$('#hosting_opis').css("background-position","top -687px");
					})
					.mouseenter(function(){	
						$('#ht_business').pulse({ speed: 400, textColors: ['#bbbbbb','#ffffcc']});
						$('#hosting_opis_inner span').hide();
						$('#hoi_business').show();
					})
					.mouseleave(function(){	
						$('#ht_business').recover(); // stops pulse
					});
$('#hosting_pro').mouseover(function(){
						$(this).css("cursor","pointer");				  
						$('#hosting_opis').css("background-position","top right");
					})
					.mouseenter(function(){	
						$('#ht_pro').pulse({ speed: 400, textColors: ['#bbbbbb','#ffffcc']});
						$('#hosting_opis_inner span').hide();
						$('#hoi_pro').show();
					})
					.mouseleave(function(){	
						$('#ht_pro').recover(); // stops pulse
					});



$('#spna').pulse({
	speed: 700,
	textColors: ['#999999','#550000']
});

$('.fadeakcije').innerfade({
	speed: 'slow',
	animationtype: 'fade', // fade ili slide
	timeout: 5000,
	type: 'random',
	containerheight: '162px'
	//type: Type of slideshow: 'sequence', 'random' or 'random_start' (Default: 'sequence'),
	//runningclass: CSS-Class which the container get’s applied (Default: 'innerfade')
	//speed: Fadingspeed in milliseconds or keywords (slow, normal or fast)(Default: 'normal'),
	//timeout: Time between the fades in milliseconds (Default: '2000'),
});

$(".lightbox").lightbox();


$('.tableholder table a').cluetip({
  ajaxCache:false,
  sticky: false,
  cluetipClass: 'jtip', 
  arrows: true, 
  dropShadow: true,
  hoverIntent: true,
  mouseOutClose: true,
  width:300, 
  hoverIntent: {
    sensitivity:  1,
    interval:     250,
    timeout:      350    
  },

closePosition: 'title',
  positionBy: 'bottomTop',
  closeText: '<img src="/inc/gfx/cluetip/cross.png" alt="close" />'
});



/*
$('a.jt:eq(0)').cluetip({
  cluetipClass: 'jtip', 
  arrows: true, 
  dropShadow: false,
  hoverIntent: false,
  sticky: true,
  mouseOutClose: true,
  closePosition: 'title',
  closeText: '<img src="cross.png" alt="close" />'
});


$('#houdini').cluetip({
    splitTitle: '|', // use the invoking element's title attribute to populate the clueTip...
                     // ...and split the contents into separate divs where there is a "|"
    showTitle: false // hide the clueTip's heading
  });
*/


















  var alternateRowColors = function($table) {

    $('tbody tr:odd').removeClass('even').addClass('odd');

    $('tbody tr:even').removeClass('odd').addClass('even');

  };



  $('table.sortable').each(function() {

    var $table = $(this);

    alternateRowColors($table);

    $('th', $table).each(function(column) {

      var findSortKey;

      if ($(this).is('.sort-alpha')) {

        findSortKey = function($cell) {

          return $cell.find('.sort-key').text().toUpperCase() + ' ' +

                                           $cell.text().toUpperCase();



        };



      }

      else if ($(this).is('.sort-numeric')) {

        findSortKey = function($cell) {

          var key = parseFloat($cell.text().replace(',', '').replace('.', ''));

          

          return isNaN(key) ? 0 : key;

        };

      }

      else if ($(this).is('.sort-date')) {

        findSortKey = function($cell) {

          return Date.parse('1 ' + $cell.text());

        };



      }

      

      if (findSortKey) {

        

        $(this).addClass('clickable').hover(function() {

          $(this).addClass('hover');

        }, function() {

          $(this).removeClass('hover');

        }).click(function() {

          var newDirection = -1;

          if ($(this).is('.sorted-desc')) {

            newDirection = 1;

          }

          var rows = $table.find('tbody > tr').get();

          $.each(rows, function(index, row) {

          row.sortKey = findSortKey($(row).children('td').eq(column));

          });

          rows.sort(function(a, b) {



            if (a.sortKey < b.sortKey) return -newDirection;



            if (a.sortKey > b.sortKey) return newDirection;



            return 0;



          });

          $.each(rows, function(index, row) {



            $table.children('tbody').append(row);

            row.sortKey = null;

          });

         $table.find('th').removeClass('sorted-asc').removeClass('sorted-desc');

          var $sortHead = $table.find('th').filter(':nth-child(' + (column + 1) + ')');

          if (newDirection == 1) {

            $sortHead.addClass('sorted-asc');

          } else {

            $sortHead.addClass('sorted-desc');

          }

          $table.find('td').removeClass('sorted').filter(':nth-child(' + (column + 1) + ')').addClass('sorted');

         alternateRowColors($table);

        });

      }

    });

  });


  });


/* OSTALE JS funkcije */

function testsearchinputFocus(obj,testNa){
	if(obj.value==testNa) obj.value="";
}
function testsearchinputBlur(obj,testNa){
	if(obj.value==="") obj.value=testNa;
}
function submitsearchform(testNa){
	if($("#topsearchfield").val()!=="" && $("#topsearchfield").val()!==testNa) {
		window.location='/search/'+$("#topsearchfield").val();
		}
	else return false;
}
