﻿if (!window.Spark) Spark=new Object();
if (!window.Spark.Web) Spark.Web=new Object();
if (!window.Spark.Web.Portal) Spark.Web.Portal=new Object();
if (!window.Spark.Web.Portal.Manufaktura) Spark.Web.Portal.Manufaktura=new Object();
if (!window.Spark.Web.Portal.Manufaktura.Menu) Spark.Web.Portal.Manufaktura.Menu=new Object();
//Color Palette
if (!window.Spark.Web.UI) Spark.Web.UI=new Object();
if (!window.Spark.Web.UI.WebControls) Spark.Web.UI.WebControls=new Object();
if (!window.Spark.Web.UI.WebControls.HTMLText) Spark.Web.UI.WebControls.HTMLText=new Object();
if (!window.Spark.Web.UI.WebControls.HTMLText.GlobalResources) Spark.Web.UI.WebControls.HTMLText.GlobalResources=new Object();
Spark.Web.UI.WebControls.HTMLText.GlobalResources.colorPalette=[
		"#a8015e","#f51361","#fd1b14","#ff690b","#ffb515","#fffc00","#e6dc44","#dbef3b","#6ebb1f","#005115",
		"#b5ddeb","#00a0c6","#084887","#e8e8ca","#d6cfc6","#60513a","#525050","#000005","#ba3522","#1b6ddd"];
//Color Palette END

var lasttime=0;

/***********/
if(window.jQuery)
{
	jQuery.fn.MyFadeIn = function(speed, callback) { 
		return this.animate({opacity: 'show'}, speed, function() { 
			if (jQuery.browser.msie)  
				this.style.removeAttribute('filter');  
			if (jQuery.isFunction(callback)) 
				callback();  
		}); 
	}; 
	 
	jQuery.fn.MyFadeOut = function(speed, callback) { 
		return this.animate({opacity: 'hide'}, speed, function() { 
			if (jQuery.browser.msie)  
				this.style.removeAttribute('filter');  
			if (jQuery.isFunction(callback)) 
				callback();  
		}); 
	};
	
	var resizeTimer = null;

	$(window).bind('resize', function() {    
		if (resizeTimer) clearTimeout(resizeTimer);    
		resizeTimer = setTimeout(RunOnResize, 100);
});

/*****************************GRYSCALE**********************************************
			$(document).ready(
		        function() 
		        {
				        $('.Header,.TopLinkLeftPane,.TopLinkRightPane,.TopLinkMediaPane,.ContentLeftPane,.MenuCss,.BottomMenuPane,.Footer').each(function() {
				              grayscale(this);
				         });
				}
		    );
*****************************KONIEC GRYSCALE**********************************************/



} 
/***********/


function RunOnResize() {    
	var d = new Date();
	if((lasttime+2000)<(d.getTime()))
	{
		AdjustBackgroundHeight();
		lasttime=d.getTime();
	}
}; 

function AdjustBackgroundHeight()
{
	if($('.ContentHolder').length>0)
	{
		var ContentMarginTop=$('.ContentHolder').css("margin-top").replace(/px/,"");
		var MapAdditionalHeight=0;
		if(ContentMarginTop<0)
			MapAdditionalHeight=-ContentMarginTop;
		var BackGroundHeight= $('.Background')[0].offsetHeight;
		var MagicHeight = 82;
		if(ContentMarginTop==/*85*/74)
			MagicHeight+=83;
		MagicHeight+=15;			
		var ContentHeight = $('.ContentHolder')[0].offsetHeight;
		if(jQuery.browser.msie)
		{
			if(jQuery.browser.version==6)
			{
				ContentHeight = $('.Content')[0].offsetHeight;
			}
		}
		var ContentOversize = (ContentHeight+MagicHeight+MapAdditionalHeight)-BackGroundHeight;

		if(ContentOversize>0)
		{
			$('.Background').height($('.Background').height()+ContentOversize);
		}else
		{
			$('.Background').height("100%");
		}
	}
}


Spark.Web.Portal.Manufaktura.Menu.AdjustShadow=function(ContentLeftPane)
{
	var LeftShadowHeight = ContentLeftPane.offsetHeight - 252;
	if(LeftShadowHeight>0)
	{
		var LeftShadow = document.getElementById('LeftShadow');
		//alert(LeftShadowHeight);
		LeftShadow.style.height=LeftShadowHeight+'px';
		//alert(LeftShadow.style.height);
		$('#LeftShadow').show();
	}
	else
		$('#LeftShadow').hide();
	AdjustBackgroundHeight();
}

Spark.Web.Portal.Manufaktura.Menu.ShowHideItem=function(source)
{
	var SubMenu = $('#'+source.id+"Sub");
	var SubMenus = $('.ShowHide');
	if(SubMenu[0].state==0)
	{
	//alert('1');
		$('#LeftShadow').hide();
		SubMenus.hide("fast");
		for(var i=0;i<SubMenus.length;i++)
			SubMenus[i].state=0;
		SubMenu.MyFadeIn("fast",function () {
          Spark.Web.Portal.Manufaktura.Menu.AdjustShadow($('.ContentLeftPane')[0]);
        });
        //SubMenu.fadeIn();

		SubMenu[0].state=1;
	}
	else
	{
	//alert('2');
		$('#LeftShadow').hide();
		SubMenu.hide("fast",function () {
          Spark.Web.Portal.Manufaktura.Menu.AdjustShadow($('.ContentLeftPane')[0]);
        });
		SubMenu[0].state=0;
	}
	//alert(SubMenu[0].state);
}

Spark.Web.Portal.Manufaktura.Menu.SubShowHideItem=function(source)
{
	var SubMenu = $('#'+source.id+"Sub");
	var SubMenus = $('.SubShowHide');
	if(SubMenu[0].state==0)
	{
		$('#LeftShadow').hide();
		SubMenus.hide("slow");
		for(var i=0;i<SubMenus.length;i++)
			SubMenus[i].state=0;
		SubMenu.show("slow",function () {
          Spark.Web.Portal.Manufaktura.Menu.AdjustShadow($('.ContentLeftPane')[0]);
        });

		SubMenu[0].state=1;
	}
	else
	{
		$('#LeftShadow').hide();
		SubMenu.hide("slow",function () {
          Spark.Web.Portal.Manufaktura.Menu.AdjustShadow($('.ContentLeftPane')[0]);
        });
		SubMenu[0].state=0;
	}

}
