/**
*	Some js
*/




$(document).ready(function(){

	if (typeof hs != "undefined") {
		hs.graphicsDir = '/js/highslide/highslide/graphics/';
		hs.outlineType = 'rounded-white';
	}


 $('a[@rel*=lightbox]').each(function() {
    this.onclick = function() {
      return hs.expand(this);
    };
 });


	if ($("#container").length > 0) {
		slider();
	}
	

	// preload top images
	
	$.preload( '.buttons img' );








	//resize();
	//$(window).trigger("resize");


	// bind toggle for cat button images

	$(".buttons img").hover(
		function(){
			if($(this).attr("src").indexOf("0") != -1) {
					var newSrc = $(this).attr("src").replace("0","1");
					$(this).attr("src" ,newSrc);
			}
		},
		function(){
			if($(this).attr("src").indexOf("1") != -1 && this.className != "active") {
				var newSrc = $(this).attr("src").replace("1","0");
				$(this).attr("src",newSrc);
			}
		}
	);




	// rollover kreisai izvēlnei

	$(".level0>li").hover(
		function(){
			if(this.className != "active") {
				this.className = this.className + " rollover";
			}
		},
		function(){
			if(this.className != "active") {
				this.className = this.className.replace("rollover", "");
			}	
		}
	);
	
	
	$(".level1>li").hover(
		function(){
			if(this.className != "active") {
				$("a", this).css("font-weight", "bold");
			}
		},
		function(){
			if(this.className != "active") {
				$("a", this).css("font-weight", "normal");
			}	
		}
	);	
	




	if($("#lielakie").length > 0 && $("#aktuali").length > 0) {
		
		resizeOnLoad();
		
	}


/*
	if($('a[@rel*=lightbox]').length > 0)
		$('a[@rel*=lightbox]').zoomimage();
*/		

});






function resize() {

	// auto height for footer

	$(window).bind("resize", function(){

		var footer = $("#footer");
		
		if(footer.length > 0)
		{
			var top = footer.offset().top;
			var wh = $(window).height();

			footer.height(wh - top);

			// IE fires resize for footer; others don't so do it here

			if ( !jQuery.browser.msie )
				footer.trigger("resize");
		}		
			
		// backgrounda bilde
			
		var bg = $("#bg div");
		
		/*
		 *  1800px - bildes izmērs
		 *  50 - mazliet offset, lai vadi neaizlien zem aktualitātes kastītes
		 */

		/*
		var w1 = 1800 + 50;
		var w2 = $(window).width();
		
		bg.css("left", w2/2 - w1/2);
		*/		
			
	});


}











function resizeOnLoad()
{

	var maxImages = $("#lielakie img").length;
	var loadedImages = 0;
	
	$("#lielakie img").each(function(nr, item){
		
		if (item.complete != true) {
			setTimeout("resizeOnLoad()", 10);
			return;
		}
		else {
			loadedImages++;
		}
			
	});	

	
	if(loadedImages != maxImages) {
			setTimeout("resizeOnLoad()", 10);
			return;
	}
	
	
	if($("#lielakie").length > 0 && $("#aktuali").length > 0) {
		
		var l = $("#lielakie").height();
		var a = $("#aktuali").height();
					
		
		if (l > a) {
			$("#aktuali").css("padding-bottom", (l - a + 5) + "px");
		}	

		if (a > l) {
			$("#lielakie").css("padding-bottom", (a - l + 5) + "px");
		}	
	}
}



