// JavaScript Document
$(document).ready(function(){

	toggleKoncepty();
	toggleProdukty();

	$('p.headingKoncepty').click(function(){
		if($("#leftmenu2").css("display") == "none"){
			$.cookie("koncepty", "1" );
			$.cookie("Produkty", "0" );
			toggleKoncepty();
			toggleProdukty();
		}else{
			$.cookie("koncepty", "0" );
			toggleKoncepty();
		};
	});
	$('p.headingProdukty').click(function(){
		if($("#leftmenu").css("display") == "none"){
			$.cookie("Produkty", "1" );
			$.cookie("koncepty", "0" );
			toggleProdukty();
			toggleKoncepty();
		}else{
			$.cookie("Produkty", "0" );
			toggleProdukty();
		};
	});
	function toggleKoncepty(){
		if($.cookie("koncepty") == 1){
			$("#leftmenu2").show();
		}else{
			$("#leftmenu2").hide();
		}
	}
	function toggleProdukty(){
		if($.cookie("Produkty") == 1){
			$("#leftmenu").show();
		}else{
			$("#leftmenu").hide();
		}
	}
	
	$('ul.menu_main').click(function(){
		if($.cookie("koncepty") == 1) {
			$.cookie("koncepty", "0" );
		}
		if($.cookie("Produkty") == 1) {
			$.cookie("Produkty", "0" );
		}
	});
	$('ul.menu_main li.first').click(function(){
		if($.cookie("koncepty") == 1) {
			$.cookie("koncepty", "0" );
		}
		if($.cookie("Produkty") == 1) {
			$.cookie("Produkty", "0" );
		}
	});
	
	randContentImage(1);
	$('#brand_list').hide();
	$('#brand_select').toggle(function(){
		$(this).css('margin-bottom','0px');
		$('#brand_list').fadeIn('normal');
	}, function(){
		$('#brand_list').fadeOut('normal',function(){
			$('#brand_select').css('margin-bottom','13px');
		});
	});
	$('#brand_list a').click(function(){
		$('#brand_list').fadeOut('normal',function(){
			$('#brand_select').css('margin-bottom','13px');
		});
	});
		/*
	$('#leftmenu2').click(function(){
		$.cookie("navigationtree", "0" );
	});
	
	$('#leftmenu').click(function(){
		$.cookie("koncepty", "0" );
	});
	$("#leftmenu1").treeview({
		animated: "fast",
		collapsed: true,
		unique: true,
		persist: "cookie",
		cookieId: "navigationtree",
		toggle: function() {
			window.console && console.log("%o was toggled", this);
		}
	});
	
	
	
	$("#leftmenu2").treeview({	
		animated: "fast",
		collapsed: true,
		unique: true,
		persist: "cookie",
		cookieId: "navigationtree1",
		toggle: function() {
			window.console && console.log("%o was toggled", this);
		}
	});
	*/
	
	//var bg = new Array("bg_main.jpg","bg_main2.jpg","bg_main3.jpg");
	//slide(bg,0);
	
	$('ul#intro').innerfade({
		speed: 1500,
		timeout: 5000,
		type: 'sequence',
		containerheight: '420px'
	});
	
});
function randContentImage(max){
	var randomNumber = Math.floor(Math.random()*max);
	$('#content').css('background','url(\'../images/bg_content_' + randomNumber + '.jpg\') no-repeat');
}
function brand_select(id){
	$('.brand_view').attr({href: id+'_brand.htm'});	
}
stopSlide = 0;
function slide(th,i){;
	i++;
	var count = th.length;
	if(i >= count)i = 0;
	setTimeout(function(){
       if(stopSlide == 0){
       	$('#pic_main').fadeOut('slow',function(){
			$(this).css({'background' : 'url(\'images/'+th[i]+'\')'}).fadeIn('slow');
		});
       	slide(th,i);
       }
	}, 7000);
}


