var $j = jQuery.noConflict();
/* functions dependent on jquery */

function mainmenu(){
$j(" #advelopesNav ul ").css({display: "none"}); // Opera Fix

$j(" #advelopesNav li").hover(function(){//rollover
	$j(this).find('ul:first').css({visibility: "visible",display: "none"}).fadeIn(400);
  	$j(this).addClass('activeHover');
  	}, function(){//rollout
  	$j(this).find('ul:first').fadeOut(50);
   	$j(this).removeClass('activeHover');
  });
}

 
 $j(document).ready(function(){     
 	mainmenu();
	//heading styling
	$j("#maincontent H3:not(H3.green, H3.sectionHeading)").before("<div class='H3Top'>&nbsp;</div>");
	$j("#maincontent H3:not(H3.green, H3.sectionHeading)").after("<div class='H3Bottom'>&nbsp;</div>");
	
	$j("#maincontent H3.green").before("<div class='H3TopGreen'>&nbsp;</div>");
	$j("#maincontent H3.green").after("<div class='H3BottomGreen'>&nbsp;</div>");
	
	$j("#maincontent H4").after("<div class='H4Bottom'>&nbsp;</div>")
	
	//news item wrapper
	$j("#maincontent DIV.newsItem").before("<div class='H3Top'>&nbsp;</div>");
	$j("#maincontent DIV.newsItem").after("<div class='H3Bottom'>&nbsp;</div>");



	//glossary first line
	$j("DIV #glossaryTerms H1:first").addClass("first");
	//glossary all tables in glossary adjust previous P spacing
	$j("DIV #glossaryTerms TABLE").prev("p").css("margin-bottom", "2px");
	//glossary attached to top	link	
	$j("#glossary h1").not(".first").before("<div class='toTop'><a href='#glossary'>to top</a></div>");

	//add icons to docs
	$j('#maincontent a[href$=".pdf"]').each(function(){
    	$j(this).wrap("<span class='pdf'></span>");
		$j(this).attr("target", "_blank");  
	}); 
	
	$j('#maincontent a[href$=".ppt"]').each(function(){
    	$j(this).wrap("<span class='ppt'></span>");
		$j(this).attr("target", "_blank");  
	}); 
	
	$j('#maincontent a[href$=".doc"]').each(function(){
    	$j(this).wrap("<span class='doc'></span>");
		$j(this).attr("target", "_blank");  
	}); 
	
	
	
	
	//tooltip stuff			
	var zmax = 50;
	
	$j('.toolTip').css({zIndex:zmax});

	$j('.toolTip').hover(
		function() {
		
		if( $j(this).is(".toolTipRegister")) {
 				 this.tip = "<strong>Register now to access our secure trade area</strong>:<br><ul><li>Upload and store artwork </li><li>Download envelope dielines </li><li>Request &amp; track quotations </li></ul>";
		} else if ($j(this).is(".toolTipLogin")){
			 this.tip = "Existing users login here"
		} else if ($j(this).is(".toolTipLogout")){
			 this.tip = "Signout of Advelopes"
		} else if ($j(this).is(".toolTipNewQuote")){
			 this.tip = "New users"
				} else {
	 		return false
		}		
		
		zmax = zmax+1;
		 		
		$j( this ).css( 'zIndex', zmax );
		
		$j(this).append(
			'<div class="toolTipWrapper">'
				+'<div class="toolTipTop">&nbsp;</div>'
				+'<div class="toolTipMid">'
					+this.tip
				+'</div>'
				+'<div class="toolTipBtm">&nbsp;</div>'
			+'</div>'
		);
		
		//get our current x y position
		var tipWrapperPos = $j(this);		
		var position = tipWrapperPos.position();		
		
		this.title = "";
		this.width = $j(this).width();
		this.height = $j(this).height();
		
		$j(this).find('.toolTipWrapper').css({left:this.width-(this.width + 145)});
		$j(this).find('.toolTipWrapper').css({top:position.top - (this.height - 11)});
		$j('.toolTipWrapper').fadeIn("slow");
	},
	function() {
		$j('.toolTipWrapper').fadeOut(100);
		$j(this).children().remove();
			this.title = this.tip;
		}
	)
	//tooltip stuff ends
	
	
	
	//tooltip 2 stuff			
	var zmax2 = 51;
	var newReq;
	
	$j('.overTooltip').css({zIndex:zmax2});

	$j('.overTooltip').hover(
		
			
		function() {
			
		if($j(this).is(".overTooltipQuote") & $j(".quoteRow2").is(":visible")) {
 			 return false;				
		} else if ( $j(this).is(".overTooltipQuote")){ 
			 this.tip = "<strong>New users,</strong> simply provide your contact details, select from the drop-down boxes and submit!";		
		} else if ($j(this).is(".overTooltipLogin")){
			 this.tip = "<strong>Existing users,</strong> login now to request a new quote or manage your existing jobs."
		} else {
	 		return false
		}		
		
		zmax2 = zmax2+1;
		 		
		$j( this ).css( 'zIndex', zmax2 );
		
		//get our current x y position
		var tipWrapperPos = $j(this);		
		var position = tipWrapperPos.position();			
		
		$j(this).append(
			'<div class="toolTipWrapperGrey">'
				+'<div class="toolTipTopGrey">&nbsp;</div>'
				+'<div class="toolTipMidGrey">'
					+this.tip 
				+'</div>'
				+'<div class="toolTipBtmGrey">&nbsp;</div>'    
			+'</div>' 
		);
		this.title = "";
		
		this.width = $j(this).find('.toolTipWrapperGrey').width();
		this.height = $j(this).find('.toolTipWrapperGrey').height();
						
		$j(this).find('.toolTipWrapperGrey').css({top:position.top - (this.height - 15)});
		$j(this).find('.toolTipWrapperGrey').css({left:position.left + (this.width - 35)});
		$j('.toolTipWrapperGrey').fadeIn("slow");
	},
	function() {
		$j('.toolTipWrapperGrey').fadeOut(100);
		$j(this).children().remove();
		this.title = this.tip;
		}
	)
	//tooltip stuff ends

	
	
	
	//quote page stuff
		$j(".quoteRow2").hide();
		$j("a.newrequest").click(function() {
				if($j(".existing").is(":visible")){
					$j(".existing").fadeOut("slow");
			    	$j(".quoteRow2").slideDown(300);
					$j(this).addClass("quoteactive");
					$j('.toolTipWrapperGrey').fadeOut(100);
					return false
				} else{
					$j('.toolTipWrapperGrey').fadeOut(100);
					$j(".quoteRow2").slideUp(300);
					$j(".existing").fadeIn("slow");
					$j(this).removeClass("quoteactive");					
					return false
				}
				
   			});
	//quote page stuff ends		
	
		
		
});