

/*popup*/
function popit(url, height, width){
  var left = parseInt((screen.availWidth/2) - (width/2));
  var top = parseInt((screen.availHeight/2) - (height/2));
  var windowFeatures = "width=" + width + ",height=" + height + ",status,scrollbars=1,resizable,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
  window.open(url, "subWind", windowFeatures);
}

$(document).ready(function(){
		
$("a.popit").click(function(e){
	e.preventDefault();
	
	var height 	= (parseInt($(this).attr("class").split(" ")[2]) + 20)
	var width 	= (parseInt($(this).attr("class").split(" ")[1]) + 23)
		
	popit($(this).attr("href"), height, width)	
})	
	

var nrOfLi = jQuery('#slider li').length;


	function mycarousel_initCallback(carousel){
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });		
    jQuery('#pager a,.pager a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });			
	};

	function highlight(carousel,obejctli,liindex,listate){     
		var nthChild = jQuery(obejctli).attr('class').split(" ");		
		jQuery('#pager a:nth-child('+ nthChild[1] +'),.pager a:nth-child('+ nthChild[1] +')').attr("class","activeSlide");
	};

	function removehighlight(carousel, obejctli,liindex,listate){
		var nthChild2 = jQuery(obejctli).attr('class').split(" ");
		nthChild2 = parseInt(nthChild2[1]);						
  	jQuery('#pager a:nth-child('+ nthChild2 +'),.pager a:nth-child('+ nthChild2 +')').removeAttr("class","activeSlide");
	};



$("#cntFishesContent div.1").css({"display":"block"});
	
	$(".js #slider img").css({
  	"display": "block"
  });	
  jQuery("#slider").jcarousel({
    scroll: 1,
		auto: 7,
		wrap: 'both',
		animation: 800,
		size: nrOfLi,
    initCallback: mycarousel_initCallback,
		itemVisibleInCallback:{
  		onBeforeAnimation: highlight  		
		},
		itemVisibleOutCallback:{
  		onBeforeAnimation: removehighlight  		
		},
    // This tells jCarousel NOT to autobuild prev/next buttons
    buttonNextHTML: null,
    buttonPrevHTML: null
  });	
	
	
	/*$('#slider').cycle({ 
    fx:     	'scrollHorz', 
    speed:  	2000,
		//speedIn: 	2000,
		//speedOut:	2000, 
    timeout: 	6000,		
		pager: 		"#pager",
		pause:		1,
		pauseOnPagerHover: 1,
		easing: 	"easeInOutExpo"						 
    //next:   '#next2', 
    //prev:   '#prev2' 
	});
	*/
	
	if($("#cntFishes .block").length > 1){
		//alert("kör")
		$('#cntFishes').cycle({ 
	    fx:     	'scrollHorz', 
	    speed:  	2000, 
	    timeout: 	0,		
			pager: 		".pager" 
	    //next:   '#next2', 
	    //prev:   '#prev2' 
		});		
	}
  if($("#cntFishes .block").length < 2){
		//alert("kör inte")
		$("#cntFishes .block").css({"display":"block"});	
	}

		
	
	/*----------------------------------FISHES-AQUARIES--------------------------------------*/
	
	$("#cntFishes .cntThumb a").click(function(e){
		e.preventDefault();
		$("#cntFishesContent div").css({"display":"none"});
		$("#cntFishes h4").removeClass("active");		
				
		$("#cntFishesContent div.fish430x260, #cntFishesContent div.fishText, #cntFishesContent div." + $(this).attr("class")).css({"display":"block"});
		$("#cntFishes h4." + $(this).attr("class")).addClass("active");
	})

	/*$(".pager a").click(function(e){
		e.preventDefault();
		
		$(".pager a").removeClass("active");
		$("#cntFishes div.block").css({"display":"none"});
		
		var hideDiv = "." + $(this).attr("class");
		$(this).addClass("active");				
		$(hideDiv).css({"display":"block"});		
	})
	*/
	
	
	$("div.cntThumb").hover(
  function () {
    $(this).children("h4").addClass("hover");
  }, 
  function () {
    $(this).children("h4").removeClass("hover");
  }
	);



	
	/*----------------------------------FISHES-AQUARIES--------------------------------------*/
		
		if($(".content img").attr("align")=="right")
			$(".content img").addClass("floatRight");
	
		if($(".content img.floatRight").length > 1){
			$(".content img.floatRight").each(function(index){
				if(index > 0)
					$(this).addClass("TM")
			})
		}
				
})
