// JavaScript Document

var TopMenu = {
  click: function() {
    // do something on click
	currentMenu = this.id;
	menuOpen = true;
	$type = 1;
  },
  mouseover: function() {
	  var cc = 0;
	  var $ab = $("body").find("#" + this.id + "-sub");
	  $ab.each(function (indexA, Elem)
	  {
		 cc ++; 
	  });
			  if(this.id!=currentMenu)
			  {
				  
				  if($type==1)
				  	$("#" + currentMenu).css("background-color", "#E8E8E8");
				  else if($type==2)
					$("#" + currentMenu).children("img").attr("src","/assets/images/" + currentMenu + ".gif");
			  }
		  $(this).css("background-color", "#F6B715");
	  if(cc>0)
	  {
		  if(menuOpen)
		  {
			  if(this.id!=currentMenu)
			  {
				  $("#" + currentMenu + "-sub").hide(500);
				  if($type==1)
				  	$("#" + currentMenu).css("background-color", "#E8E8E8");
				  else if($type==2)
					$("#" + currentMenu).children("img").attr("src","/assets/images/" + currentMenu + ".gif");
				  $("#" + this.id + "-sub").show(500);
				  $(this).css("background-color", "#F6B715");
			  }
		  }
		  else
		  {
			  $("#" + this.id + "-sub").show(500);
			  
			  
			  $(this).css("background-color", "#F6B715");
			  $("#menuImage").stop();
			  $("#menuImage").clearQueue();
			  $("#headerSpacer").stop();
			  $("#headerSpacer").clearQueue();
			  $("#subMenu").stop();
			  $("#subMenu").clearQueue();
			  $("#headerSpacer").animate({
					   
						width: "443px"
						//opacity: 'toggle'
					  }, 500, 'linear');
			  $("#menuImage").animate({
					   
						width: "443px"
						//opacity: 'toggle'
					  }, 500, 'linear');
			  $("#subMenu").animate({
					   
						width: "310px"
						//opacity: 'toggle'
					  }, 500, 'linear');	
		  }
	  }
  },
  mouseout: function() {
	  var cc = 0;
	  var $ab = $("body").find("#" +  this.id + "-sub");
	  $ab.each(function (indexA, Elem)
	  {
		 cc ++; 
	  });
			if(this.id!=currentMenu)
			{  
			  $(this).css("background-color", "#E8E8E8");
			}
				  if($type==1)
				  	$("#" + currentMenu).css("background-color", "#F6B715");
				  else if($type==2)
					$("#" + currentMenu).children("img").attr("src","/assets/images/" + currentMenu + "-over.gif");
			
	  if(cc>0)
	  {
	  
		  if(!menuOpen)
		  {
			  $("#" + this.id + "-sub").hide(500);
			  $(this).css("background-color", "#E8E8E8");
			  $("#menuImage").stop();
			  $("#menuImage").clearQueue();
			  $("#headerSpacer").stop();
			  $("#headerSpacer").clearQueue();
			  $("#subMenu").stop();
			  $("#subMenu").clearQueue();
			  $("#headerSpacer").animate({
					   
						width: "753px"
						//opacity: 'toggle'
					  }, 500, 'linear');
			  $("#menuImage").animate({
					   
						width: "753px"
						//opacity: 'toggle'
					  }, 500, 'linear');
			  $("#subMenu").animate({
					   
						width: "0px"
						//opacity: 'toggle'
					  }, 500, 'linear');
		  }
		  else
		  {
			if(this.id!=currentMenu)
			{  
			  $("#" + this.id + "-sub").hide(500);
			  $(this).css("background-color", "#E8E8E8");
			}
			  $("#" + currentMenu + "-sub").show(500);
				  if($type==1)
				  	$("#" + currentMenu).css("background-color", "#F6B715");
				  else if($type==2)
					$("#" + currentMenu).children("img").attr("src","/assets/images/" + currentMenu + "-over.gif");
		  }
	  }
  }
};

var SideMenu = {
  click: function() {
    // do something on click
	currentMenu = this.id;
	menuOpen = true;
	$type = 2;
  },
  mouseover: function() {
	  var cc = 0;
	  var $ab = $("body").find("#" + this.id + "-sub");
	  $ab.each(function (indexA, Elem)
	  {
		 cc ++; 
	  });
	  
		if(this.id!=currentMenu)
		{
		  
		  if($type==1)
			$("#" + currentMenu).css("background-color", "#E8E8E8");
		  else if($type==2)
			$("#" + currentMenu).children("img").attr("src","/assets/images/" + currentMenu + ".gif");
		}
		$(this).children("img").attr("src","/assets/images/" + this.id + "-over.gif");

	  if(cc>0)
	  {
		  
		  
		  if(menuOpen)
		  {
			  if(this.id!=currentMenu)
			  {
				if(currentMenu!="loja")
				  $("#" + currentMenu + "-sub").hide(500);
				  if($type==1)
				  	$("#" + currentMenu).css("background-color", "#E8E8E8");
				  else if($type==2)
					$("#" + currentMenu).children("img").attr("src","/assets/images/" + currentMenu + "-over.gif");
				if(this.id!="loja")
				  $("#" + this.id + "-sub").show(500);
				  
				  $(this).children("img").attr("src","/assets/images/" + this.id + "-over.gif");
			  }
		  }
		  else
		  {
				if(this.id!="loja")
				{
					  $("#" + this.id + "-sub").show(500);
					  
					  
					  $("#menuImage").stop();
					  $("#menuImage").clearQueue();
					  $("#headerSpacer").stop();
					  $("#headerSpacer").clearQueue();
					  $("#subMenu").stop();
					  $("#subMenu").clearQueue();
					  $("#headerSpacer").animate({
							   
								width: "443px"
								//opacity: 'toggle'
							  }, 500, 'linear');
					  $("#menuImage").animate({
							   
								width: "443px"
								//opacity: 'toggle'
							  }, 500, 'linear');
					  $("#subMenu").animate({
							   
								width: "310px"
								//opacity: 'toggle'
							  }, 500, 'linear');	
				}
		  }
	  }
  },
  mouseout: function() {
	  var cc = 0;
	  var $ab = $("body").find("#" +  this.id + "-sub");
	  $ab.each(function (indexA, Elem)
	  {
		 cc ++; 
	  });
			if(this.id!=currentMenu)
			{  
				  $(this).children("img").attr("src","/assets/images/" + this.id + ".gif");
			}
			  if($type==1)
				  $("#" + currentMenu).css("background-color", "#F6B715");
			  else if($type==2)
				  $("#" + currentMenu).children("img").attr("src","/assets/images/" + currentMenu + "-over.gif");
			  
	  if(cc>0)
	  {
	  
		  if(!menuOpen)
		  {
			 if(this.id!="loja")
			 	  $("#" + this.id + "-sub").hide(500);
			  $(this).children("img").attr("src","/assets/images/" + this.id + ".gif");
			 
				if(this.id!="loja")
				{			 
					  $("#menuImage").stop();
					  $("#menuImage").clearQueue();
					  $("#headerSpacer").stop();
					  $("#headerSpacer").clearQueue();
					  $("#subMenu").stop();
					  $("#subMenu").clearQueue();
					  $("#headerSpacer").animate({
							   
								width: "753px"
								//opacity: 'toggle'
							  }, 500, 'linear');
					  $("#menuImage").animate({
							   
								width: "753px"
								//opacity: 'toggle'
							  }, 500, 'linear');
					  $("#subMenu").animate({
							   
								width: "0px"
								//opacity: 'toggle'
							  }, 500, 'linear');
				}
		  }
		  else
		  {
			  
			if(this.id!=currentMenu)
			{  
				if(this.id!="loja")
			 	 $("#" + this.id + "-sub").hide(500);
				  $(this).children("img").attr("src","/assets/images/" + this.id + ".gif");
			}
			if(currentMenu!="loja")
			  $("#" + currentMenu + "-sub").show(500);
			  if($type==1)
				  $("#" + currentMenu).css("background-color", "#F6B715");
			  else if($type==2)
				  $("#" + currentMenu).children("img").attr("src","/assets/images/" + currentMenu + "-over.gif");
		  }
	  }
  }
};

var TopMenuSub = {
  click: function() {
    // do something on click
	  var cc = 0;
	currentSubMenu = $(this).children("a").attr("id");
	subMenuOpen = true;
  },
  mouseenter: function() {
	  var cc = 0;
  },
  mouseleave: function() {
	  var cc = 0;
  }
}
