var current = false;
var firstTime = true;
var galleryPos = 10;
var showHidePanel = true;
var scrolls = [];
var hideStage = false;
var currentOver = 0;
var hm;
var currentPanel;
function showPanel(what){
	var d1 = what ? 'block' : 'none';
	var d2 = !what ? 'block' : 'none';
	$('#desc').css('display', d1);
	$('#desc-link').css('display', d2);
	showHidePanel = what;
}
function showPanelFlash(what){
	var d = what ? 'block' : 'none';
	if(showHidePanel){
		$('#desc').css('display', d);
	} else {
		$('#desc-link').css('display', d);
	}
	$(".download-but").css('display', d);
	$(".bl-buts").css('display', d);
	$(".fbBox").css('display', d);
}
$(function(){
	$('#desc').hover(function(){
		/*$(this).addClass('desc-hover');*/ 
		var fade = (current == "#gallery") ? 1 : 0.9;
		$(this).fadeTo(300, fade);
	},function(){
		/*$(this).removeClass('desc-hover');*/ 
		var fade = (current == "#gallery") ? 0.1 : 0.7;
		$(this).fadeTo(300, fade);
	});
	$('div.fbBox').hover(function(){
		/*$(this).addClass('desc-hover');*/ 
		$(this).fadeTo(300, 1);
	},function(){
		/*$(this).removeClass('desc-hover');*/ 
		$(this).fadeTo(300, .5);
	});
    $("ul.dropdown li").hover(function(){
        $(this).addClass("hover");
		$(this).parent().find('ul').css('visibility', 'hidden');
        $('ul:first',this).css('visibility', 'visible');
		$('a:first', this).addClass("hover");
		$('div a:first', this).removeClass("hover");
		$('#overStage').css('display', 'block');
		clearTimeout(hm);
		hideStage = false;
		if($('.over-prod .pic', this) && $('.over-prod .left', this).height() > $('.over-prod .pic', this).height()){
			var h =  $('.over-prod .left', this).height();
			$('.over-prod .pic', this).css('height', h);
		}
		
    }, function(){
       // $('ul:first',this).css('visibility', 'hidden');
		$('a:first', this).removeClass("hover");
		hideStage = true;
		hm = setTimeout('hideOverStage()', 1000)
    });
	document.onclick = function(){hideOverStage(true)};
   // $("ul.dropdown li ul li:has(ul)").find("a:first").append(" &raquo; ");
   //$("ul.dropdown li ul li:has(ul)").find("a:first").css("color", "#fff");
   if( $('ul.rootList > li').length == 1)
		$('ul.rootList > li a').click();
});
function showTopMenu(){
	 
}
function hideOverStage(a){
	if(hideStage || a){
		$('#overStage').css('display', 'none');
		$("ul.dropdown ul").css('visibility', 'hidden');
		$("ul.dropdown li").removeClass("hover");
		$("ul.dropdown li").css("z-index", '500');
	}
}
function changeOverPic(pic, txt, catId, itemId, who){
	//$('div.over-prod div.right img').attr("src", pic);
	$('#overDiv'+catId+' div.pic').css("background-image", "url("+pic+")");
	$('#overDiv'+catId+' div.bottom h1 span').html( txt );
	$('#overDiv'+catId+' .left a').css("color", "#999999");
	$(who).css("color", "#ffffff");
	var mainLink = '?menu=product&id='+itemId;
	$('#menuCat'+catId+' #overviewLink').attr('href', mainLink+'#overview');
	$('#menuCat'+catId+' #specificationLink').attr('href', mainLink+'#specification');
	$('#menuCat'+catId+' #geometryLink').attr('href', mainLink+'#geometry');
	$('#menuCat'+catId+' #galleryLink').attr('href', mainLink+'#gallery');
	$('#menuCat'+catId+' #qaLink').attr('href', mainLink+'#qa');
	$('#menuCat'+catId+' #buildLink').attr('href', mainLink+'#build');
	$('#menuCat'+catId+' #buyLink').attr('href', mainLink+'#buy');
}

function setSpecButs(box){
	current = box;
	if(firstTime){
		firstTime = false;
		setDescWH(current+"-panel #scrollbar1 .overview");
		$(current+"-panel").css('visibility', 'visible');
	}
	$('.bottom ul li a').click(function(e){
		$(current+'-panel').css('visibility', 'hidden');
		current = this.hash || '#overview';
		setTimeout('setNewBox()', 200);
		setDescWH(current+"-panel #scrollbar1 .overview");
	});
	
}
function setNewBox(){
	$(current+'-panel').css('visibility', 'visible');
}
function zoomBig(pic){
	showPanel(false);
	//$('.prod').css('background-position', '10px 5px')
}
function changePic(pic) {
	//$('div.prod').css('background-image', 'url(templates/site/pictures/'+pic+'_small.jpg')
    callFlash("prod").changePic(pic);
}

function callFlash(id) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[id]
    }
    else {
		if(document[id].length != undefined){
          return document[id][1];
      }
        return document[id]
    }
}
function setLinkDnl(pic){
	$(".download-but a").attr("href", "templates/site/pictures/"+pic+".jpg");
}
/*
function setScroll(who){
	if(firstTime){
		scrolls.push(who);
	}
	if(scrolls.length){
		for(var i=0; i<scrolls; i++){
			if(who != scrolls[i]){
				scrolls.push(who);
				$(who+' #scrollbar1').tinyscrollbar();	
			}
		}
	}
}*/
function setScrollHidden(targ){
	if(!$(targ +'-panel #scrollbar1 .thumb').height()){
		$(targ +'-panel #scrollbar1 .viewport').css('width', 295);
		$('.prod-gallery img').css('width', 145);
		$('#geometry-panel img').css('width', 288);
	}
}
function setDescWH(box){
	var desc = "#desc";
	var bottom = "#desc .bottom"
	var maxH = 478;
	var h = $(box).height()+$(bottom).height()+40;
	if(h>maxH){
		h=maxH;
	}
	h = parseInt(h)+'px';
	//$(desc).css({width:w, height:h});
	$(desc).animate({height:h});
}
function setLangs(){
	var oldt;
	$('.langs').hover(function(){
		showLangs(true, $('this'));
		oldt = $('.langs h1').html();
	},function(){
		showLangs(false, "");
	});
	$('.langs-over a').hover(function(){
		$('.langs h1').html($(this)[0].rel);
	},function(){
		$('.langs h1').html(oldt);
	});
	$('.langs').css('width', $('.langs-over ul').width()+60);
	$('.langs-over li:first').css('border-right', '1px solid #666');
	$('.langs-over').fadeTo(50, 0);
}
function showLangs(what, targ){
	var w = what ? 200 : 0;
	var fade = what ? 1 : 0;
	$('.langs-over').fadeTo(200, fade);
	//$('.langs-over').animate({width:w});
}
function setFaceIcons(){
	//$('.fbBox img').css('width', 20)
}
function debug(what){
	if(window.console){
		console.log(what);
	}	
}
function showFAQ(nums){
	var n = nums || 4;
	$('.page-title a').click(function(){
		var h = (this.hash == "#all") ? 0 : this.hash.substring(2);
		if(h){
			for(var i=1; i<=n; i++){
				$('#faq'+i).css('display', 'none');
			}
			$('#faq'+h).css('display', 'block');
		} else {
			for(var i=1; i<=n; i++){
				$('#faq'+i).css('display', 'block');
			}
		}
		$('#scrollbarG').tinyscrollbar();
	})
}
function setTeamMenu(num){
	var active = num || 1;
	$('#team'+active).css('display', 'block');
	$('#scrollbarG').tinyscrollbar();
	$('#t'+active).addClass('active');
	$('.gallery-title a').click(function(){
		var a = this.id.substring(1);
		$('#t'+active).removeClass('active');
		$('#team'+active).css('display', 'none');
		active = a;
		$('#team'+active).css('display', 'block');
		$(this).addClass('active');
		$('#scrollbarG').tinyscrollbar();
	})
}
function showHideList(targ, nums){
	var d = (currentPanel != targ) ? "block" : "none";
	var uw = 270*nums;
	var t = "#"+targ;
	$(".list1-panel-bgr").css('display', 'none');
	$(t).css('display', d);
	if(d == "block"){
		currentPanel = targ;
		$(t+' ul').css('width', uw+'px');
		$(t+' div.list1-panel').css('width', uw+'px');
		$(t+' #scrollbar-list-panel').tinyscrollbar({ axis: 'x'});
	} else {
		currentPanel = undefined;
	}
}

