﻿var z = "";
$(function() {
	
	$("a.external").bind("click", function() {
		
		window.open($(this).attr('href'));
		return false;
		
	});
	
	//traverse active
	jQuery.each($(".menu .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");

	});
	$("ul.dropdown li").bind("click", function() {
		var linkObj = $(this).find("a");
		if($(linkObj).attr('href')!="") {
			if($(linkObj).hasClass('external')) {
				window.open($(linkObj).attr('href'));
			} else {
				document.location.href = $(linkObj).attr('href');
			}
		}
	
	});


	

	// 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");
					}
				});
			}
		); 
	}
	


	// show bottom stuff
	$("#bottomLogo").css('display','block');
	$("#bottomTxt").css('display','block');
	$("div#bottom").css({'display' : 'block', 'position' : 'fixed'});		
	$("#sitemap").css('left',
		1077-$("#sitemap").width() + 'px'
	);
	
	var bottomHeight = $("#sitemap").height();
	
	$("#bottom").css({
	'bottom' : '-' + bottomHeight-20 + 'px',
	'height' : bottomHeight + 50 + 'px'
	});

	$("#bottomTxt").bind('click', function() {
		if($("#bottom").css('bottom')=="-" + bottomHeight-20 + "px") {
			$("#bottomTxt").animate({
				'top': 820-bottomHeight + 50 + 'px'
			},{
				duration: 600,
				easing: 'easeOutCirc'
			});
			$("#bottom").animate({
				'bottom': '0px',
				'opacity' : 0.95
			},{
				duration: 600,
				easing: 'easeOutCirc'
			});
		} else {
			$("#bottomTxt").animate({
				'top': '820px'
			},{
				duration: 550,
				easing: 'easeOutCirc'
			});
			$("#bottom").animate({
				'bottom': '-' + bottomHeight-20 + 'px',
				'opacity' : 1
			},{
				duration: 1200,
				easing: 'easeOutCirc'
			});
		}
		
		return false;
	});	
	if($("#nav li a[class='active']").parent('li').length>0) menuEffect_createIt($("#nav li a[class='active']").parent('li'),'mr-arrow.gif',96,'menuEffect_top',z,0);	
});﻿


function menuEffect_createIt(obj,imgSrc,newPosY,divId,timeVar,offsetX) {
	clearTimeout(timeVar)	;
	var newPosX = $(obj).offset().left + Math.floor(($(obj).width()/2)+offsetX) + 'px';
	
	if(!document.getElementById(divId)) {
		var menuEffect = "<img id=\"" + divId + "\" src=\"/gfx/template/" + imgSrc + "\" class=\"menuEffect\" />";
		$("body").append(menuEffect);
		$("#" + divId)
		.css({ 'display' : 'block', 'opacity' : 0, 'left' : newPosX, 'top' : parseInt(newPosY + $(obj).height()) + 'px' })
		.animate({ 'opacity' : 1, 'top' : newPosY}, 400);
	} else {
		$("#" + divId)
		.animate({ 'left' : newPosX}, { duration: 200, easing: 'easeOutQuad' });		
	}
	
	
}

function menuEffect_returnIt(divId,menuContainer,offsetX) {
		var obj = $(menuContainer + " li a[class='active']").parent('li');
		var newPosX = $(obj).offset().left + Math.floor(($(obj).width()/2)+offsetX) + 'px';
		$("#" + divId)
		.animate({ 'left' : newPosX}, { duration: 200, easing: 'easeOutQuad' });	
}

function menuEffect_killIt(divId) {
		$("#" + divId)
		.animate({ 'opacity' : 0}, 200, function() { $(this).remove(); });	
}



function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

