﻿var menuExpanded = 0;
$(function() {
	
	$(document).scrollTop(0);
	$("li[class='active'] a").css('color','#fff');

	$("#menuBtn").bind('click', function() { toggleMenu(); });
	
	
	$("body").append(
		"<div style=\"position: absolute; z-index: 9999; background: #000; border: 1px solid #c0c0c0; padding: 20px 20px 15px 20px\" id=\"tmpLoader\">" + 
			"<img src=\"/ajax_loader_888888.gif\" />" +
		"</div>"
	);	
	$("#tmpLoader").css({
		'top': parseInt(($("body").height()-$("#tmpLoader").height())/2) + 'px',
		'left': parseInt(($("body").width()-$("#tmpLoader").width())/2) + 'px'
	
	});	
	
	if($("#galleries div ul").length > 0) {
		$("body").append("<div class=\"modalOverlay\" id=\"modalOverlay\"></div>");
		$("#modalOverlay")
		.css({
			'width': '100%',
			'height': '100%',
			'opacity':0.7
		});
	}
	if($("#galleries").length>0) {
		if($("#txtP").html().length==0) {
			$("#galleries").css('width',Math.floor($(document).width()-100) + 'px');
		} else {
			$("#galleries").css('width',Math.floor($(document).width()-370) + 'px');
		}
	}
	
	
	var tmp = location.href;
	if(tmp.substring(tmp.length-1,tmp.length)=="/") {
		animate_bottom();
		$("#menuBg")
		.css({ 'opacity': 0.7, 'left': '-' + $("#menus ul").width() + 'px' })
		.animate({ 'left' : '0px' }, {duration:3000})
		.animate({ 'left' : '-' + ($("#menus ul").width()+10) + 'px' }, {duration:1500});
		//.animate({ 'left': '-' + parseInt($("#menuBg").width()-140) + 'px' });		
	} else {
		$("#menuBg")
		.css({ 'opacity': 0.7, 'left' : '-' + ($("#menus ul").width()+10) + 'px'  });
		

		$("body").css('overflow','auto');
	

		if($("#txtP").html().length > 0) {
			$("#txtP")
			.css({
				'display': 'block',
				'right': '15px'
			})
			$("#txt").css({
				'right' : '0px', 
				'opacity' : 0.8
			});
		} else {
			$("#txt").css('display','none');
		}

		if($("#custom_bgImg").length>0) {
			$("body").css({
			"background": "url(/files/" + $("#custom_bgImg").attr('value') + ") right top",
			"backgroundAttachment": "fixed"		
			});
			$("#tmpLoader").fadeOut('normal').remove();
		}		

	}	
	

	
	
	
	// 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

		
		$("div.gal a").colorbox({
			'current': "billede {current} af {total}",
			'bgOpacity': '0.8',
			'transition': 'fade',
			'maxHeight': '90%'
		});		

		// 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");
					}
				});
			}
		); 
	}	
	$("#menuBgBlack").css('height',($(document).height()+20)+'px');
	
	if($("#customImg").length>0) {
		if($("#customImg img").length>1) {
			customImgFolder('init');
		} else {
			$("#customImg img").css('display','block');
		}
	}			
});

var customImgArr = "";
var curr_customImg = 0;
var customImg_time = 2500;
var customImg_delay = 2000;
function customImgFolder(cmd) {
	switch(cmd) {
		case "init":
			customImgArr = $("#customImg img").length-1;
			curr_customImg = customImgArr;
			$("#customImg img:last").css('display','block');
			setTimeout("customImgFolder('')",customImg_delay);
		break;
		case "":
			var tmp = curr_customImg;
			curr_customImg = (curr_customImg==0) ? curr_customImg = customImgArr : curr_customImg = curr_customImg-1;
			$("#customImg img").css('zIndex','0');
			$($("#customImg img").get(tmp)).css('zIndex','1');
			$($("#customImg img").get(curr_customImg)).css({ 'opacity' : 0, 'zIndex' : '2', 'display' : 'block' })
			.animate({ 'opacity' : 1 }, {duration : customImg_time, complete: function() {
				setTimeout("customImgFolder('')",customImg_delay);
			}});
			
			
		break;
	}
}  		

function toggleMenu() {
	if(menuExpanded==0) {
		$("#menuBg")
		.animate({ 'left' : '0px' }, {duration:500});
		menuExpanded = 1;
	} else {
		$("#menuBg")
		.animate({ 'left' : '-' + ($("#menus ul").width()+10) + 'px' }, {duration:500});	
		menuExpanded = 0;
	}
}


function animate_bottom() {

	if($("#custom_bgImg").length>0) {
		$("body").css({
		//"background": "url(/files/" + $("#custom_bgImg").attr('value') + ") 50% 50% no-repeat",
		"background": "url(/files/" + $("#custom_bgImg").attr('value') + ")",
		"backgroundAttachment": "fixed"		
		});
		$("#tmpLoader").fadeOut('normal').remove();
	}


	
	$("#txtP").css({'right':'-500px','display': 'none'});
	$("#txt")
	.css('opacity',0);
	if($("#txtP").html().length > 0) {
		$("#txtP")
		.css('display','block')
		.animate({ 'right' : '60px'},500);
		$("#txt").animate(
		{ 'right' : '45px', 'opacity' : 0.8},
		{duration: 1500, easing: 'easeOutQuad', complete: function() {
				}
			}
		)		
	}


}
