//styles
Cufon.replace('#subnav a, .tjanst h3, .tjanst h4', { fontFamily: 'TradeGothic' });
Cufon.replace('.tjanst h1', { fontFamily: 'TradeGothic Light' });



var iLoadNextPictureAfterSec = 0;  //0 doesnt load next picture
var iFadeInOutSec = 0.5;  //0 no fade (iFadeInOutSec*2 must be smaller than iLoadNextPictureAfterSec)
bRandomLoad = 1;
var aThemes = new Array();
aThemes[0] = '/images/bigpic_start_1_gp.jpg';
aThemes[1] = '/images/bigpic_start_2_gp.jpg';
aThemes[2] = '/images/bigpic_start_3_gp.jpg';


 var prevThemePic = -1;
 var bRandomLoad = 1;
 function ThemePic() {
	/* IMAGES IS LOADED ON defatul.htm */
	/*var aThemes = new Array(2);
            aThemes[0]= 'images/pic_page_start_theme1a.jpg';
            aThemes[1]= 'images/pic_page_start_theme1a.jpg';*/
  var RndPic = 0;
  if(prevThemePic == -1){
		if(bRandomLoad){
			RndPic = Math.floor(Math.random()*aThemes.length);
		}
	}
	else{
		RndPic = prevThemePic + 1;
		if(RndPic >= aThemes.length) { RndPic = 0;}
	}
	
	if(iFadeInOutSec > 0 && prevThemePic > -1 && aThemes.length > 1){
		$("#theme-pic-holder").fadeOut(iFadeInOutSec*1000, function(){
				$("#theme-pic-holder").css("background-image", "url(" + aThemes[RndPic] + ")");
				$("#theme-pic-holder").fadeIn(iFadeInOutSec*1000);
		});
	}
	else {
		$("#theme-pic-holder").css("background-image", "url(" + aThemes[RndPic] + ")");
	}
	
	//OLD - loading of picture
	/*var objThemePicHolder = document.getElementById("themePicHolder")
	if (objThemePicHolder){
		objThemePicHolder.style.backgroundImage = "url(" + aThemes[RndPic] + ")";
	}*/
	prevThemePic = RndPic;
	
	if(iLoadNextPictureAfterSec > 0){
		LoadThemePic();
	}
}

function LoadThemePic() {
	setTimeout('ThemePic()', iLoadNextPictureAfterSec*1000);
}



$(document).ready(function(){

	$("#subnav a").click(function(){
		bBubbleLocked = (!bBubbleLocked);
		speechBubble($(this), true);
	}); 
	
	$("#subnav a").mouseover(function(){
		speechBubble($(this), true);
	});
	
	
	$(".hide-speech-bubble").click(function(){
		bBubbleLocked = false;
		speechBubble($(this), false);
	});
	
	$(".hide-speech-bubble").mouseover(function(){
		speechBubble($(this), false);
	});
	
	
	setSpeechBubbleArrow();
});



var ACTIVATE_LOCK = false;
var bBubbleLocked = false;
var bSlideIn = false;
var bSlideOut = true;
function speechBubble($obj, bShow) {
	var id = "tjanster_" + $obj.attr("id");
	if(bShow) {
		if($(".tjanst:visible").size() > 0){
		//if(!bSlideOut) {
			$(".tjanst").hide();
			$("#" + id).show();
		}
		else {
			$(".tjanst").hide();
			$("#" + id).show("blind", { direction: "horizontal" }, 500, function(){ bSlideOut = false; });
		}
		bSlideIn = true;
	}
	else if(!ACTIVATE_LOCK || (ACTIVATE_LOCK && !bBubbleLocked)) {
		if(bSlideIn) {
			bSlideIn = false;
			bSlideOut = true;
			$(".tjanst:visible").hide("blind", { direction: "horizontal" }, 500, function(){ $(".tjanst").hide(); });
		}
	}
}



function setSpeechBubbleArrow() {
    var iExtraOffsetTop = 0;
    if ($(".ie6 #global-message:visible").size() > 0) {
        iExtraOffsetTop = $("#global-message").height() + parseInt($("#global-message").css("padding-top").replace("px", "")) + parseInt($("#global-message").css("padding-bottom").replace("px", ""));
        var iTop = iExtraOffsetTop + parseInt($(".tjanst").css("top").replace("px", ""));
        $(".tjanst").css("top",iTop + "px");
    }
	$("#subnav a").each(function(){
		var id = "tjanster_" + $(this).attr("id");
		var iOffsetTop = parseInt($(this).offset().top) - iExtraOffsetTop;
		$arrow = $("#" + id + " .speech-arrow div");
		if($arrow.size() > 0){
			var iMarginTop = iOffsetTop + parseInt($arrow.css("margin-top").replace("px", "")) - 280;
			$arrow.css("margin-top", iMarginTop + "px");
		}
	});
}

