var initialHeight = 550;
    $('.historyContent').hide();
    $('#spillersHistoryContent').show();

$(document).ready(function (){

    $("#menuTop .lv1").hoverIntent({
        sensitivity: 7,
        interval: 100,
        timeout: 100,
        over: function() {
            if ($(this).children().children("div").attr("class") == "button") {
                $(this).children().children("div").classAddOn();
            }
            $(this).children().children().show();
        },
        out: function() {
            $(this).children().children("div").classRemoveOn();
            $(this).children().children("ul").hide();
            $(this).children(".boxLeft").hide();
            $(this).children(".boxRight").hide();
        }
    });

	
	$(".menuTopBar span").mouseover(function (){
		var boxLeft = $(this).parent().next();
		var boxRight = $(this).parent().next().next();
		if($(this).attr("class") == "left"){
			boxLeft.show();
			boxRight.hide();
		}
		else if($(this).attr("class") == "right"){
			boxLeft.hide();
			boxRight.show();
		}
	});
	
	$(".boxLeft li, .boxRight li, .box li").hover(function (){
		$(this).toggleClass("on");
	},function (){
		$(this).toggleClass("on");
	});
	
	
	/* Brands bar */
	$("#brandsBar ul li img[class!=separator]").hover(function (){
		$(this).srcAddOn();
	},function (){
		$(this).srcRemoveOn();
	});
	    
	/* Left Menu */    
	$("li[class*='Lv2'] div").click(function(){
          var __targetElt = $("li[class*='" + this.className + "']");
          if($(__targetElt).attr("state") == "undefined" || $(__targetElt).attr("state") == 1)
          {    	
	        $(this).children("img").replaceFileName("arrowRight");
            $(__targetElt).hide();
	        $(__targetElt).removeAttr("state")
	  }else{
	        $(this).children("img").replaceFileName("arrowDown");
            $(__targetElt).show();
            $(__targetElt).attr("state", 1)
          }
	});
	
	/* Tabs */
	$("#tabs ul li[class!=separator]").click(function (){
		var value = $(this).attr("value");
		if(value != -1 && value != 0){
			$(".contents, .imageContents, .textContents").hide();
			$("#tabs ul li[class!=separator][class!=shadow][class!=firstShadow][class!=empty]").removeClass();
			$(this).toggleClass("on");
			$("#tab"+value).show();
		}
	});
	
	/* Content opener */
	$(".openContent, .openContentFirst").click(function() {
	    if ($(this).attr("title").toLowerCase() == "open") {

	        $(this).classAddOn();
	        $(this).children(".right").children(".link").children("span").text(__arrayCmd[1]);
	        $(this).children(".right").children("img").replaceFileName("arrowRedDown");
	        $(this).next().show();
	        $(this).attr("title", "Close");



	        /* FIXED */
	        height = $(".contents").height();
	        height = height + 125;

	        if (height > initialHeight) {
	            $("#innerContent").css("height", height + "px");
	            $("#content").css("height", height + "px");
	        }

	    }
	    else if ($(this).attr("title").toLowerCase() == "close") {
	        $(this).classRemoveOn();
	        $(this).children(".right").children(".link").children("span").text(__arrayCmd[0]);
	        $(this).children(".right").children("img").replaceFileName("arrowRight");
	        $(this).next().hide();
	        $(this).attr("title", "Open");


	        /* FIXED */
	        height = $(".contents").height();
	        height = height + 125;

	        if (height < initialHeight) {
	            height = initialHeight;
	        }



	        /* This is the fix for the ie7 footer problem */
	        $("#innerContent").css("height", height);
	        $("#content").css("height", (height - 84));
	    }
	});

	
	$(".content .contentBar .right").click(function (){
		var openContent = $(this).parent().parent().prev()
		openContent.classRemoveOn();
		openContent.children(".right").children(".link").html("[&nbsp;<u>"+__arrayCmd[0]+"</u>&nbsp;]");
		openContent.children(".right").children("img").replaceFileName("arrowRight");
		openContent.attr("title","Open");
		openContent.next().hide();
		
		
	        /* FIXED */
	        height = $(".contents").height();
	        height = height + 125;

	        if (height < initialHeight) {
	            height = initialHeight;
	        }



	        /* This is the fix for the ie7 footer problem */
	        $("#innerContent").css("height", height);
	        $("#content").css("height", (height - 84));

	});
	
	
	/* info bar search field */
	$("input[name=search]").focus(function (){
		if($(this).val() == "search"){
			$(this).val("");
		}
	});
	
	$("input[name=search]").blur(function (){
		if($(this).val() == ""){
			$(this).val("search");
		}
	});
	
	
	/* Content Brand */
	
	$(".contentBrand").click(function (){
		$(this).next().next().toggle();
		$(this).hide();
		
	});
	
	$(".contentBrandOpen img").click(function (){
		if($(this).attr("title") == __arrayCmd[1]){
			$(this).parent().parent().prev().prev().show();
			$(this).parent().parent().hide();
		}
	});
	
	
	/* FAQ */
	
	$("#faq .question, #faq .firstQuestion").click(function (){
		$(this).openQuestion();
	});
	
	$("#faq .viewAll").click(function (){
		$(".answer").show();
		$(".question, .firstQuestion").each(function (){
			$(this).openQuestion();
		});
	});
	
	
	/* Community FAQ */
	
	$("#communityFaq .question, #communityFaq .firstQuestion").click(function (){
		$(this).openQuestion();
	});
	
	$("#communityFaq .viewAll").click(function (){
		$(".answer").show();
		$(".question, .firstQuestion").each(function (){
			$(this).openQuestion();
		});
	});
	
	
	/* History */
	
	$(".history, .historyLast").click(function (){
		$(this).hide();
		$(this).next().show();
	});	
	
	$(".historyOpen .close").click(function (){
		var historyDiv = $(this).parent().parent().parent()
		
		historyDiv.hide();
		historyDiv.prev().show();
	});
	
    $("#historyLogos img").bind('mouseover mouseout',function (){
		$(this).srcToggleOn();
	});
	
    $('#historyLogos img').click(function (){
        $('.historyContent').hide();
        $('#'+$(this).attr('cid')+'Content').show();
    });


	/* Partnership */
	
	$(".partnership .partner, .partnership .firstPartner").click(function (){
		$(this).openPartner();
		
	});

	$(".partnership .contentBar .right").click(function (){
		$(this).parent().parent().prev().prev().openPartner();
	});
	
});


$.fn.openQuestion = function (){
	var result = $(this).classToggleOn();
	var arrow = $(this).children(".right").children("img");
	var link = $(this).children(".right").children(".link");
		
	if(result == true){
		fileName = "arrowDown";
		$(this).next("[class=answer]").show();
		$(this).next().next("[class=answer]").show();
		linkStr = "[&nbsp;<u>close answer</u>&nbsp;]";
		divTitle = "Close";
	}
	else{
		fileName = "arrowRight";
		$(this).next("[class=answer]").hide();
		$(this).next().next("[class=answer]").hide();
		linkStr = "[&nbsp;<u>view answer</u>&nbsp;]";
		divTitle = "Open";
	}
	
	$(this).attr("title",divTitle);
	link.html(linkStr)
	arrow.replaceFileName(fileName);
}


$.fn.openPartner = function (){

		var result = $(this).classToggleOn();
		var arrow = $(this).children(".right").children("img");
		var link = $(this).children(".right").children(".link").children("u");
		
		if(result == true){
			fileName = "arrowDown";
			$(this).next().next().show();
			linkStr = "close partner";
			divTitle = "Close";
		}
		else{
			fileName = "arrowRight";
			$(this).next().next().hide();
			linkStr = "open partner";
			divTitle = "Open";
		}
	
		$(this).attr("title",divTitle);
		link.text(linkStr)
		arrow.replaceFileName(fileName);

}



