// JavaScript Document
var nav_active = "";
var accnav_active = "";
var accnav_open = "";
var accnav_over = false;
var int_acc = 0;
var int_npol = 0;

var browser = "";
var version = "";


// brosercheck
var arr_browser = new Array();
jQuery.each(jQuery.browser, function(i, vall) {
	
	arr_browser.push([i, vall]);
});


// browser
var num = 0;
while(num < arr_browser.length)
{
	if(arr_browser[num][1] == true)
	{
		browser = arr_browser[num][0];
		break;
	}
	num++;
}
// version
version = arr_browser[1][1];
//alert("version: "+version);
//alert("browser: "+browser+" - version: "+version+" - "+version.substr(0,1));
	
	
$(document).ready(function(){ 
	$(document).pngFix(); 
	RO.rollover.init();
	RO_acc.rollover.init();
	RO_acc_bg.rollover.init();
	RO_nav.rollover.init();
	RO_duftnav.rollover.init();
	RO_npol.rollover.init();
	RO_startarrow.rollover.init();
	
/*
	accnav_active = $('#dbnav4');
	accnav_open = $('#dbnav4').parent().parent();
	accnav_active.css({'left':"-160px"});	
*/
//	$("dd:not(:last)").hide();
//	$("dd").hide();
	setAccFuncs();
	
	
	
	if(browser == "msie" && Number(version.substr(0,1)) <= 6)
	{
		var offset = $("#footer_main").offset();
		var top = offset.top;		
		var h =  $(document).height()-40;
		$("#footer_main").css({"top":h+"px","position":"absolute"});
	}
	$("#footer_main").css("display","block");
	


	$("a[rel='#overlay']").overlay({
		top: "0px",
		oneInstance: true, 
		fixed: false,
		/*closeOnClick: false, */
		onBeforeLoad: function() {		
			var that= this,
			wrap = this.getOverlay().find(".contentWrap"); 
			wrap.load(this.getTrigger().attr("href"), function(){
															   
				$(this).parent().find("#overlay_bg").click(function(e){
					e.preventDefault();
					that.close();
				}),
				
				$(this).find("#overlay_close_btn").click(function(e){
					e.preventDefault();
					that.close();
				})
				
			});
		}
	});

	$('div.toGewinnspiel').click(function() {
		window.location = "/gewinnspiel/kraftikus/start";
	});


	$('div.kraftikus_icon').click(function() {
		window.location = "/gewinnspiel/kraftikus/wirkstoff/"+$(this).attr('rel');
	});


/*$('a.new-window').click(function(){
window.open(this.href);
return false;
});
*/
});


/* accordion */
function setAccFuncs()
{
	$("dt").hover(function()
	{
		clearInterval(int_acc);
		accnav_over = true;
		
		if($(this).next().is(":hidden"))
		{
			$("dd:visible").slideUp("slow");
			$(this).next().slideDown("slow");			
		}
		return false;
	},
	function()
	{
		accnav_over = false;
		if(accnav_open != "" && checkId($(this)) == false)
		{
			var bla = $(this);
			int_acc = setInterval(function callFunc() { closeAcc("dt", bla) }, 500);
		}
		return false;
	}
	
	);

	$("dd").hover(function()
	{
		clearInterval(int_acc);
		accnav_over = true;
		return false;
	},
	function()
	{
		accnav_over = false;
		if(accnav_open != "" && checkId($(this).prev()) == false)
		{
			var bla = $(this);
			int_acc = setInterval(function callFunc() { closeAcc("dd", bla) }, 500);
		}
		return false;
	});
}

function closeAcc(val, e)
{
	clearInterval(int_acc);

	if(accnav_over == false)
	{
		switch(val)
		{
			case "dt":
			e.next().slideUp("slow");
			
			accnav_open.next().slideDown("slow");
			break;
		
			case "dd":
			e.slideUp("slow");
			accnav_open.next().slideDown("slow");
			//alert(accnav_over+" - closeAcc: "+val+" - "+e);
			break;
		}
	}
}

function checkId(e)
{
	val1 = e.find("img").attr('id');
	val2 = accnav_open.find("img").attr('id');

	//alert(val1+" - "+val2);

	if(val1 == val2)
		t = true;
	else
		t = false;

	return t;
}
/* --- */


/* rollover function for navi produkt overlay*/
RO_npol = {};
RO_npol.rollover =
{
	init: function()
	{
		$(".ro_npol").hover(
			function ()
			{
				if($(this).attr('id') != "opener")
				{
					var bmi = $(this).find(".overlay_milk");
					// browsercheck
					if(browser != "msie")// || (browser == "msie" && version.substr(0,1) > 6)
					{	
						$(bmi).fadeOut(500);//animate({opacity: 0}, 500 );
					}
					else if(browser == "msie")// && version.substr(0,1) > 6
					{
						$(bmi).css("display","none");
					}
				}
				stopCloseProductNavi();
			},
			function ()
			{
				if($(this).attr('id') != "opener")
				{
					var bmi = $(this).find(".overlay_milk");
					if(browser != "msie")//|| (browser == "msie" && version.substr(0,1) > 6)
					{	
						$(bmi).fadeIn(500);//animate({opacity: 1}, 500 );
					}
					else if(browser == "msie")// && version.substr(0,1) > 6
					{
						$(bmi).css("display","block");
					}
				}
				startCloseProductNavi();
			}
		);
		
		$('.ro_npol').click(
			function ()
			{
				openProductNavi();
			}
		);
	}
};

/* rollover function for all JPGs*/
RO_startarrow = {};
RO_startarrow.rollover =
{
	init: function()
	{
		$(".ro_startarrow").hover(
			function ()
			{
				$(this).css({'left':"-100px"});
			},
			function ()
			{
				$(this).css({'left':'0px'});
			}
		);
		
		$('.ro_startarrow').click(
			function ()
			{
				
			}
		);
	}
};


/* rollover function for all JPGs*/
RO = {};
RO.rollover =
{
	init: function()
	{
		$(".ro").hover(
			function ()
			{
				w = $(this).attr('width')/2;
				$(this).css({'left':"-"+w+"px"});
			},
			function ()
			{
				$(this).css({'left':'0px'});
			}
		);
		
		$('.ro').click(
			function ()
			{
				
			}
		);
	}
};	

/* rollover function for duftbarometer-accordion*/
RO_acc = {};
RO_acc.rollover =
{
	init: function()
	{
		$(".ro_acc").hover(
			function ()
			{
				w = $(this).attr('width')/2;
				$(this).css({'left':"-"+w+"px"});
			},
			function ()
			{
				w = $(this).attr('width')/2;
				if($(accnav_active).attr('id') == $(this).attr('id'))
					$(this).css({'left':"-"+w+"px"});
				else
					$(this).css({'left':'0px'});
			}
		);
		
		$('.ro_acc').click(
			function ()
			{
				setActiveAccNavi($(this));
			}
		);
	}
};

RO_acc_bg = {};
RO_acc_bg.rollover =
{
	init: function()
	{
		$(".ro_acc_bg").hover(
			function ()
			{
				num = $(this).attr('id').slice(4);
				v = $("#dbnav"+num);
				w = v.attr('width')/2;
				v.css({'left':"-"+w+"px"});
			},
			function ()
			{
				num = $(this).attr('id').slice(4);
				v = $("#dbnav"+num);
				w = v.attr('width')/2;
				if($(accnav_active).attr('id') == v.attr('id'))
					v.css({'left':"-"+w+"px"});
				else
					v.css({'left':'0px'});
			}
		);
		/*
		$('.ro_acc_bg').click(
			function ()
			{
				num = $(this).attr('id').slice(4);
				v = $("#dbnav"+num);
				setActiveAccNavi(v);
			}
		);
		*/
	}
};	

/* rollover function for main-navi with PNGs*/
RO_nav = {};
RO_nav.rollover =
{
	init: function()
	{
		$('.ro_nav').hover(
			function ()
			{
				$(this).css({'left':'-167px'});
			},
			function ()
			{
				if($(nav_active).attr('id') == $(this).attr('id'))
					$(this).css({'left':'-167px'});
				else
					$(this).css({'left':'0px'});
			}
		);
		
		$('.ro_nav').click(
			function ()
			{
				setActiveNavi($(this));
			}
		);
	}
};	

/* rollover function for duftwelten navi with PNGs*/
RO_duftnav = {};
RO_duftnav.rollover =
{
	init: function()
	{
		$('.ro_duftnav').hover(
			function ()
			{
				$(this).css({'left':'-100px'});
			},
			function ()
			{
				//if($(nav_active).attr('id') == $(this).attr('id'))
			//		$(this).css({'left':'-100px'});
			//	else
					$(this).css({'left':'0px'});
			}
		);		
	}
};	


function loadContent(url, div, val){
	
	//$('#'+div).html('<div id="ajaxloader"><img src="images/ajax-loader.gif" width="32" height="32" alt="Lade"><br />Lade Inhalt</div>');
	//$('#content').load(url + " #content_in_zielseite");
	//$('#'+div).load('include/'+url+'.php?val='+val);
	
	$(div).load('include/'+url+'.php'+ " "+val);
}


function setActiveNavi(e)
{
	if($(nav_active).attr('id') != "")
		$(nav_active).css({'left':'0px'});

	nav_active = e;

	if($(nav_active).attr('id') != "" && $(nav_active).attr('id') != "logo")
		$(nav_active).css({'left':'-167px'});
};

function setActiveAccNavi(e)
{
	if($(accnav_active).attr('id') != "")
		$(accnav_active).css({'left':'0px'});

	accnav_active = e;
	accnav_open = e.parent().parent();
	//alert("id: "+accnav_open.attr('id'));
	$(accnav_active).css({'left':'-160px'});

	setActiveNavi($('#nav2'));
	
	//loadContent("duftwelten", 'content');
};

function startCloseProductNavi()
{
	clearInterval(int_npol);
	int_npol = setInterval(closeProductNavi,800);
}

function stopCloseProductNavi()
{
	clearInterval(int_npol);
}

function openProductNavi()
{
	clearInterval(int_npol);
	$("#nav_overlay_produkt_liste")
		.animate( { height:115, top:21 }, { queue:true, duration:200, easing:"easeIn" } )
		.animate({ width:700 }, { duration:200, easing:"easeOut" });		
}

function closeProductNavi()
{
	clearInterval(int_npol);
	$("#nav_overlay_produkt_liste")
		.animate( { width:100 }, { queue:true, duration:200, easing:"easeIn" } )
		.animate({ height:20, top:0 }, { duration:200, easing:"easeOut" });		
}

$(function() {
        $('.zoom a').lightBox();
    });


