$(document).ready(function() {

	$('#tmkItemRotator').flash({
		swf: '/inc/flash/tmkItemRotator/tmkItemRotatorH18.swf',
		width: 420,
		height: 145,
		quality : "high",
		scale: "noscale",
		wmode: "transparent",
		play: "true",
		flashvars: { 
			xmlfile: "/inc/flash/tmkItemRotator/akcijaXML.php"
			//,L1Color: "0x000000"
			//,L2Color: "0xffffff"
			//,L3Color: "0x000000"
			}
	});
	

	$("#kforma textarea").focus(function(){$(this).parent(".textarea_container").addClass("focus");})
						 .blur(function(){$(this).parent(".textarea_container").removeClass("focus");});
	$("#kforma input").focus(function(){$(this).addClass("focus");})
						 .blur(function(){$(this).removeClass("focus");});

/*
$('.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'),
});
*/

//-- Slider --//
	var fadeakcije = $('#fadeakcije').bxSlider({
			speed: 800,
			controls: false,
			mode: 'vertical',
			pager: false
	});
	//-- SliderThumbs --//
	var fadeakcije_thumbs = $('#fadeakcije_thumbs').bxSlider({
			auto: true,
			mode: 'vertical',
			speed: 800,
			pager: false,
			pause: 6000,
			prevSelector: '#fadeakcije_prev',
			nextSelector: '#fadeakcije_next',
			displaySlideQty: 4,
			autoHover: true,
			onNextSlide: function(currentSlide, totalSlides){
					fadeakcije.goToNextSlide();
			},
			onPrevSlide: function(currentSlide, totalSlides){
					fadeakcije.goToPreviousSlide();
			},
			onAfterSlide: function(currentSlide, totalSlides, slideElement){
					$('#fadeakcije_thumbs a').removeClass('pager-active');
					slideElement.find('a').addClass('pager-active');
			}
	});
	//-- SliderThumbs Navigation --//
	$(function(){                   
			$('#fadeakcije_thumbs a').bind('click', function(event) {
					
					var currentSlideNum = $(this).parent().parent().index();
					var totalSlides = fadeakcije_thumbs.getSlideCount();
					
					if(currentSlideNum > totalSlides) {
							currentSlideNum = currentSlideNum - totalSlides;
					}
					
					currentSlideNum = currentSlideNum - 1;
					
					$('#fadeakcije_thumbs a').removeClass('pager-active');
					$(this).parent().find('a').addClass('pager-active');
					
					fadeakcije_thumbs.goToSlide(currentSlideNum);
					fadeakcije.goToSlide(currentSlideNum);
					
					return false;
			});
	});
                        
   //-- Slider Pause On Hover --//
	$(function(){
			$('#fadeakcije').hover(
			  function () {
				fadeakcije_thumbs.stopShow();
			  }, 
			  function () {
				fadeakcije_thumbs.stopShow();
			  }
			);
			
			return false;
	});




/* http://bxslider.com/ */
$('.sliderAkcija.odd').bxSlider({
	infiniteLoop: true,									// true, false - display first slide after last
	controls: false,                     // true, false - previous and next controls
	speed: 1000,                         // integer - in ms, duration of time slide transitions will occupy
	easing: 'easeOutExpo',                    // used with jquery.easing.1.3.js - see http://gsgd.co.uk/sandbox/jquery/easing/ for available options
	auto: true,                        // true, false - make slideshow change automatically
	autoDirection: 'next',              // 'next', 'prev' - direction in which auto show will traverse
	autoStart: true,                    // true, false - if false show will wait for 'start' control to activate
	autoHover: false,                    // true, false - if true show will pause on mouseover
	autoDelay: 0,                       // integer - in ms, the amount of time before starting the auto show
	pause: 5000,                        // integer - in ms, the duration between each slide transition
	startingSlide: 0,                   // integer - show will start on specified slide. note: slides are zero based!
	displaySlideQty: 3,                 // integer - number of slides to display at once
	moveSlideQty: 2,                    // integer - number of slides to move at once
	randomStart: false                 // true, false - if true show will start on a random slide
				});
$('.sliderAkcija.even').bxSlider({
	infiniteLoop: true,									// true, false - display first slide after last
	controls: false,                     // true, false - previous and next controls
	speed: 1000,                         // integer - in ms, duration of time slide transitions will occupy
	easing: 'easeOutExpo',                    // used with jquery.easing.1.3.js - see http://gsgd.co.uk/sandbox/jquery/easing/ for available options
	auto: true,                        // true, false - make slideshow change automatically
	autoDirection: 'prev',              // 'next', 'prev' - direction in which auto show will traverse
	autoStart: true,                    // true, false - if false show will wait for 'start' control to activate
	autoHover: false,                    // true, false - if true show will pause on mouseover
	autoDelay: 2000,                       // integer - in ms, the amount of time before starting the auto show
	pause: 5000,                        // integer - in ms, the duration between each slide transition
	startingSlide: 0,                   // integer - show will start on specified slide. note: slides are zero based!
	displaySlideQty: 3,                 // integer - number of slides to display at once
	moveSlideQty: 2,                    // integer - number of slides to move at once
	randomStart: false                 // true, false - if true show will start on a random slide
				});
	
	
	
	
/*
$.fn.textWidth = function(){
  var sensor = $('<div />').css({margin: 0, padding: 0});
  $(this).append(sensor);
  var width = sensor.width();
  sensor.remove();
  return width;
};
$.fn.textWidth = function(){
  var html_org = $(this).html();
  var html_calc = '<span>' + html_org + '</span>'
  $(this).html(html_calc);
  var width = $(this).find('span:first').width();
  $(this).html(html_org);
  return width;
};
To use this mini plugin, simply:

$('.calltoaction').textWidth();
*/

function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}

equalHeight($(".dvije_recenzije_body"));






//$('.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']
});



$(".lightbox").lightbox();


$('.tableholder table a').cluetip({
  ajaxCache:false,
  sticky: false,
  cluetipClass: 'roundedH18', /*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;
}

