$(document).ready(function(){

	//INITIAL VARIABLES
	panel_open = false;
	
	//OPEN PAGE CATEGORY
	$(".menu_category:contains('Media')").children("div").css("background-image","url('/images/system/arrow_selected.png')");
	$(".menu_category:contains('Media')").next("ul").css("display","block");
	$(".menu_category:contains('Media')").next("ul").children("li:contains('Videos')").addClass("sub_category_selected");

	
	//PANEL
	
	$(".panel_footer_btn_action").click(function () {
		if(panel_open)
		{
			$(".panel_container").animate({"top": "-=250px"}, "slow", function() {
			
				$(".panel_footer_btn_image").attr({
					"src":"/images/panel/login.png",
					"alt":"Login",
					"title":"Login"
				});
				$(".panel_footer_btn_action span").html("Login");
											
				panel_open= false;
			});
		}
		else
		{
			$(".panel_container").animate({"top": "+=250px"}, "slow", function() {
				$(".panel_footer_btn_image").attr({
					"src":"/images/panel/close.png",
					"alt":"Close",
					"title":"Close"
				});
				$(".panel_footer_btn_action span").html("Close");
					
				panel_open= true;
			});
		}
	});
	
	$(".panel_footer_btn_action").bind("mouseenter",function(){
		$(".panel_footer_btn_action").css("color","#FFFFFF");
		if(panel_open)
		{
			$(".panel_footer_btn_action > img").attr("src","/images/panel/close_over.png");				
		}
		else
		{
			$(".panel_footer_btn_action > img").attr("src","/images/panel/login_over.png");	
		}
		}).bind("mouseleave",function(){
		$(".login_footer_btn_action").css("color","#E2E2E2");
		if(panel_open)
		{
			
			$(".panel_footer_btn_action > img").attr("src","/images/panel/close.png");
		}
		else
		{
			$(".panel_footer_btn_action > img").attr("src","/images/panel/login.png");	
		}
	});	
	
	//TOP MENU
	$(".top_menu_center > a").css({backgroundPosition: "0px 58px"}).hover(
		function() {
			$(this).stop().animate({backgroundPosition:"(0px 0px)"}, {duration:500});
		}, function() {
			$(this).stop().animate({backgroundPosition:"(0px 58px)"}, {duration:500});
		});
	
	//MENU
		//MENU SUB-CATEGORY	
		$(".sub_category_selected").prev().css("border-bottom","1px #999999 solid");
		
		$(".body_container_menu li").css({backgroundPosition: "0px 0px"}).hover(
			function() {
				$(this).stop().animate({backgroundPosition:"(-216px 0px)"}, {duration:250});
			}, function() {
				$(this).stop().animate({backgroundPosition:"(0px 0px)"}, {duration:250});
			});
		
		$(".menu_category").click(function () {
			$(".body_container_menu ul").slideUp('fast');
			$(".menu_category div").css("background-image","url('/images/system/arrow.png')"); 
			$(this).children("div").css("background-image","url('/images/system/arrow_selected.png')"); 
			$(this).next().stop().slideDown('fast');
			$(this).next().css("overflow","");
		});
		
	//TIP
	$(".tip").hover(
		function() {
			$("#tip_holder").css('top', $(this).position().top-($(this).height()/2));
			$("#tip_holder").css('left', $(this).position().left+($(this).width()*1.5));
			$("#tip_text").html($(this).attr('title').replace(/\|/i,'<br />'));
			$(this).attr('title','');
			$("#tip_holder").css('visibility','visible');
		}, function() {
			$("#tip_holder").css('visibility','hidden');
			$(this).attr('title',$("#tip_text").html().replace(/<br \/>/i,'|'));
		});
		
	//BUTTON
	$(".button").hover(
		function() {
			$(".button_left").css("background-image","url('/images/system/btn_left_over.png')");
			$(".button_right").css("background-image","url('/images/system/btn_right_over.png')"); 
			$(".button_body").css("background-image","url('/images/system/btn_body_over.png')");
		}, function() {
			$(".button_left").css("background-image","url('/images/system/btn_left.png')");
			$(".button_right").css("background-image","url('/images/system/btn_right.png')"); 
			$(".button_body").css("background-image","url('/images/system/btn_body.png')");
		});
		
	//PROGRESS BAR
	$("#progressbar").progressbar({ value: 5 });
});

$(window).load(function(){

	//IE PANEL FIX
	var IEwidth = 0;
	
	$('.panel_footer_btn_bg').children().each(function() {
		IEwidth += $(this).outerWidth();
	});
	$('.panel_footer_btn_bg').width(IEwidth);
	IEwidth = 0;
	$('.panel_footer_btn').children().each(function() {
		IEwidth += $(this).outerWidth();
	});
	$('.panel_footer_btn').width(IEwidth);
	
});
