﻿$(function() {
	
	$("a.external").bind("click", function() {
		
		window.open($(this).attr('href'));
		return false;
		
	});

	
	//traverse active
	jQuery.each($(".active"), function() {
	
		$($(this).parent("ul").parents("li:eq(0)")).parent("ul").parents("li:eq(0)").addClass("active");
		$(this).parent("ul").parents("li:eq(0)").addClass("active");

	});
	var hackIsClicked = false;
	$("ul.dropdown li").bind("click", function() {
		if(hackIsClicked==false) {
			var linkObj = $(this).find("a");
			if($(linkObj).attr('href')!="") {
				if($(linkObj).hasClass('external')) {
					window.open($(linkObj).attr('href'));
				} else {
					hackIsClicked = true;
					document.location.href = $(linkObj).attr('href');
				}
			}
		}
	});

		$("#subs li.dir ul").css('display','none');
		$("#subs li.dir.active ul").css('display','block');



	// gallery start
	if($("div.gal").length>0) {
		
		$("#gal_switch_label").html(fLang.m.gal.switchView);
		
		// // gallery type 1
		// $("div.gal img").css("opacity",0.8);
		// $("div.gal img").hover(
			// function() { $(this).stop().animate({ 'opacity' : 1}, 300); },
			// function() { $(this).stop().animate({ 'opacity' : 0.8}, 300); }
		// );
		
		// init images

		$.fn.colorbox.settings.transition = "fade";
		$.fn.colorbox.settings.bgOpacity = "0.8";
		$.fn.colorbox.settings.contentCurrent = fLang.m.gal.imageCurrentOutOfTotal;
		$("div.gal a").colorbox();		

		// switch view		
		$("a.switch_thumb").toggle(
			function(){
				$(this).addClass("swap");
				$("ul.display").fadeOut("fast", function() {
					if($("ul.display").hasClass("thumb_view")) {
						$(this).fadeIn("fast").removeClass("thumb_view");
					} else {
						$(this).fadeIn("fast").addClass("thumb_view");
					}
				});
			}, 
			function () {
				$(this).removeClass("swap");
				$("ul.display").fadeOut("fast", function() {
					if($("ul.display").hasClass("thumb_view")) {
						$(this).fadeIn("fast").removeClass("thumb_view");
					} else {
						$(this).fadeIn("fast").addClass("thumb_view");
					}
				});
			}
		); 
	}

	$("#nav li ul li").hover(
		function() { $(this).find('a:first').css('color','#ca4135'); },
		function() { $(this).find('a:first').css('color','#000'); }
	).css('color','#000');
	
	if($("#frontPictures img").length>1) {
		customImgFolder('init');
	}	
});﻿

var customImgArr = "";
var curr_customImg = 0;
var customImg_time = 2000;
var customImg_delay = 3000;
function customImgFolder(cmd) {
 
	switch(cmd) {
		case "init":
			customImgArr = $("#frontPictures img").length;
			curr_customImg = customImgArr;
			//$("#customImg img").css('display','block');
			setTimeout("customImgFolder('')",customImg_delay);
		break;
		case "":
			var tmp = curr_customImg;
			curr_customImg = (curr_customImg==0) ? curr_customImg = customImgArr-1 : curr_customImg = curr_customImg-1;
			$("#frontPictures img").css('zIndex','0');
			$($("#frontPictures img").get(tmp)).css('zIndex','1');
			$($("#frontPictures img").get(curr_customImg)).css({ 'opacity' : 0, 'zIndex' : '2', 'display' : 'block' })
			.animate({ 'opacity' : 1 }, {duration : customImg_time, complete: function() {
				setTimeout("customImgFolder('')",customImg_delay);
			}});
			
			
		break;
	}
}
