jQuery(function($) {
	 
	$(".pc-loc").hover(
		function(){
	       $(this).css({"border":"1px solid #000000"});	
		},
		function(){
		   $(this).css({"border":"1px solid #A8B8C8"});
		}
	);
	
	$(".pc-loc").focus(function(){
		$(this).css({"border":"1px solid #000000"});
	});
	
	var $selectedItem = $("div#menu-items a[selecteditem='1']");
	$selectedItem.css({'background':'#2F5F80','color':'#FFFFFF','text-shadow':'0 -1px 0 #000'});
	
	function imageLoc_hoverIn($img){
		var path = "/site/vrJinja/css/images/";
		if ($img.attr("src").indexOf("down") != -1){
		   $img.attr("src",path + "arrow2-down-over.png");
		}else{
			 $img.attr("src",path + "arrow2-up-over.png");
		}
	}
	
	function imageLoc_hoverOut($img){
		var path = "/site/vrJinja/css/images/";
	   	if ($img.attr("src").indexOf("down") != -1){
	        $img.attr("src",path + "arrow2-down.png");
		}else{
			 $img.attr("src",path + "arrow2-up.png");
	    }
	}
	
	$(".localizationWidgetWrapper span.span-wrapper").hover(
	   function (){
		   var $this = $(this);
		   imageLoc_hoverIn($this.children(".imageLoc"));
		   $this.children(".changeLocation").css({'text-decoration':'underline','color':'#000000'});
	   },
	   function (){
		   var $this = $(this);
		   var $divLocalize = $this.siblings(".localize");
		   var $changeLocation = $this.children(".changeLocation");
		   imageLoc_hoverOut($this.children(".imageLoc"));
		   if ($divLocalize.is(':visible')){
			   $changeLocation.css({'color':'#000000'});  
		   }else{
			   $changeLocation.css({'text-decoration':'none','color':'#38729C'});
		   }
	   }
	);
	
	$('.localizationWidgetWrapper span.span-wrapper, .cancel-postal-code,').click(function(){
    	
    	var path = "/site/vrJinja/css/images/";
    	var $this = $(this);
    	
    	if (!$this.hasClass("cancel-postal-code")){
    		var $divLocalize = $this.siblings(".localize");
    		if (!$divLocalize.is(':visible')){
    			$span = $this;
    			$span.data('bgColor',$this.children(".changeLocation").css('background-color'));
    			$span.css({'background':'#F3F3F4','color':'#333333','border-top-left-radius':'7px','border-top-right-radius':'7px','border':'1px solid #CAD0D8','border-bottom':'none','padding':'2px 5px 2px 5px'});
				$span.children(".imageLoc").attr("src",path + "arrow2-up.png");
				$span.trigger("blur");
    		}
    	}else{
    	    var	$divLocalize = $this.parents(".localize");
    	}
		  
    	$divLocalize.toggle('blind',function(){
			if (!$divLocalize.is(':visible')){
				if ($this.hasClass("cancel-postal-code")){
				   var $span = $this.parents(".localizationWidgetWrapper").children("span.span-wrapper");
				}else{
					var $span = $this;
				}
				$span.css({'background-color':$span.data('bgColor'),'color':'#38709A','border-top-left-radius':'0','border-top-right-radius':'0','padding':'0px','border':'none'});
				$span.children(".imageLoc").attr("src",path + "arrow2-down.png");
				$span.trigger("blur");
				$span.children(".changeLocation").css({"color":"#38729C"});
			}else{
				  if ($this.hasClass("span-wrapper")){
					  $span = $this;
					  $span.children(".changeLocation").css({"color":"#000000"});
				  }
				  if ($this.parents("#head").length){
					  if (!jQuery.browser.msie){
					      var parentOffset = $this.offset();
						  $divLocalize.offset({left:parentOffset.left});
					  }else{
						$divLocalize[0].style.left = $this[0].offsetLeft +"px";
					  }
				  }else{
					  if (!jQuery.browser.msie){
						  var parentOffset = $this.offset();
						  $divLocalize.offset({left:parentOffset.left-($divLocalize.width()-$this.width())-10});
					  }else{
						  $divLocalize[0].style.left = ($this[0].offsetLeft -($divLocalize.width()-$this.width())-9) +"px";
					  }
				  }
		     }
       });
        return false;
    });
	
	$("#user-settings span.span-wrapper").hover(
	   function (){
		   var $this = $(this);
		   var path = "/site/vrJinja/css/images/";
		   var $image = $this.children(".img-auto-username");
		   var $containerSettings = $("#container-settings");
		   if ($containerSettings.is(':visible')){
			   $image.attr("src",path + "arrow2-up-over.png");
		   }else{
		       $image.attr("src",path + "arrow2-down-over.png");
		   }
		   $this.children(".auto-username").css({'text-decoration':'underline','color':'#000000'});
	   },
	   function (){
		   var $this = $(this);
		   var path = "/site/vrJinja/css/images/";
		   var $containerSettings = $("#container-settings");
		   var $image = $this.children(".img-auto-username");
		   var $autoUsername = $this.children(".auto-username");
		   if ($containerSettings.is(':visible')){
			   $autoUsername.css({'text-decoration':'none','color':'#000000'});  
			   $image.attr("src",path + "arrow2-up-over.png");
		   }else{
			   $autoUsername.css({'text-decoration':'none','color':'#38729C'});
			   $image.attr("src",path + "arrow2-down.png");
		   }
	   }
	);
	 
    $("#user-settings span.span-wrapper").live("click",function(){
    	var $this = $(this);
    	var path = "/site/vrJinja/css/images/";
    	var $containerSettings = $("#container-settings");
    	var $userSettings = $("#user-settings");
    	var $separator = $this.parent().siblings(".separator1");
    	
    	if (!$containerSettings.is(':visible')){
    		$this.data('color',$this.css('color'));
    		$this.css({'color':'#000000'});
    		$this.children(".img-auto-username").attr("src",path + "arrow2-up-over.png");
			$userSettings.css({'background':'#E2E6EC','border-top-left-radius':'5px','border-top-right-radius':'5px'});
			$separator.css({"visibility":"hidden"});
    	}
    	if (jQuery.browser.msie){
    		$("#container-settings").width($("#user-settings").width()+15);
    		if (!$containerSettings.is(':visible')){
    			$containerSettings.css({"height":"auto"});
    			$containerSettings.slideDown('slow');
    		}else{
    			$containerSettings.animate({ "height":"1px" },"slow",function(){
                     $(this).hide();
                     var $autoUsername = $this.children(".auto-username");
         			 $autoUsername.css({'text-decoration':'none','color':'#38729C'});
         			 $userSettings.css({'background':'#FFFFFF','border-top-left-radius':'0','border-top-right-radius':'0'});
         			 $this.children(".img-auto-username").attr("src",path + "arrow2-down.png");
         			 $separator.css({"visibility":"visible"});
                 });
    		}
    	}else{ 
	    	$containerSettings.slideToggle('slow',function(){
	    		if (!$containerSettings.is(':visible')){
	    			var $autoUsername = $this.children(".auto-username");
	    			$autoUsername.css({'text-decoration':'none','color':'#38729C'});
	    			$userSettings.css({'background':'#FFFFFF','border-top-left-radius':'0','border-top-right-radius':'0'});
	    			$this.children(".img-auto-username").attr("src",path + "arrow2-down.png");
	    			$separator.css({"visibility":"visible"});
	    		}	
	    	});
    	}
	});
    
    $("#open-session").live("click",function(){
    	$this = $(this); 
    	var $separator = $this.parents("#session-close").find(".separator1");
    	
        var $loginBox = $("#login-box");
        if (!$loginBox.is(':visible')){
           if (jQuery.browser.msie){	
              $this.parent().css({'border':'1px solid #CCF','border-bottom':'none'});
              $this.css({'background':'#f3f3f4','border-top-left-radius':'5px','border-top-right-radius':'5px','padding-left':'8px','padding-right':'8px', 'padding-top':'5px','padding-bottom':'7px', 'color':'#000','z-index':'103','text-decoration':'none'});
           }else{
        	   $this.css({'border':'1px solid #CCF','border-bottom':'none','background':'#f3f3f4','border-top-left-radius':'5px','border-top-right-radius':'5px','padding-left':'8px','padding-right':'8px', 'padding-top':'5px','padding-bottom':'7px', 'color':'#000','z-index':'103','text-decoration':'none'});
           }
           $separator.css({"visibility":"hidden"});
        }
        if (jQuery.browser.msie){
    		if (!$loginBox.is(':visible')){
    			$loginBox.css({"height":"auto"});
    			$loginBox.slideDown('slow');
    		}else{
    			$loginBox.animate({ "height":"1px" },"slow",function(){
                     $(this).hide();
                     $this.css({'background':'#FFF','border-top-left-radius':'0','border-top-right-radius':'0','border':'none','color':'#38709A'});
  	        	     $this.parent().css({'border':'none'});
  	        	     $separator.css({"visibility":"visible"});
                 });
    		}
    	}else{ 
	        $loginBox.slideToggle('slow',function (){
	        	if (!$loginBox.is(':visible')){
	        	   $this.css({'background':'#FFF','border-top-left-radius':'0','border-top-right-radius':'0','border':'none','color':'#38709A'});
	        	   $this.parent().css({'border':'none'});
	        	   $separator.css({"visibility":"visible"});
	            }
	        });
    	}
        return false;
    }); 
});


