/**
*	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, .slides 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);
			}
		}
	);



	
	$('a.toggle').hover(function(){
		
		var i = $('img', this);
		i.attr('src', i.attr('src').replace('.jpg', '-active.jpg'));
		
	}, function(){
	
		var i = $('img', this);
		i.attr('src', i.attr('src').replace('-active', ''));
		
	})



/*
	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");
		}	
	}
}




