﻿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 no-repeat",
			"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

		$.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");
					}
				});
			}
		); 
	}	
	$("#menuBgBlack").css('height',($(document).height()+20)+'px');
});  		

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",
		"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() {
				}
			}
		)		
	}


}