var $j = jQuery.noConflict(); 

//header help button
$j(function(){
	$j('a#needhelp').click(function(){$j('#helpPanel').slideToggle(); return false;});
	$j('a#closeHelp').click(function(){$j('#helpPanel').slideToggle(); return false;});
	$j('#helpPanel').css('display', 'none');
});// JavaScript Document

$j(function(){
	//$j("#cartDisplay").animate({ opacity: "show" }, "slow");
	$j('#cartCount, #cartLink').hover(function(){$j('#cartDisplay').animate({ opacity: "show" }, "slow");},
	function(){$j('#cartDisplay').animate({ opacity: "hide" }, "slow");});
});// JavaScript Document


//wholesale page form reveal button
$j(function(){
	$j('a#wholesaleEmailButton, #wholesaleTrigger').click(function(){$j('div.wholesaleForm').slideToggle(); return false;});
	//$j('div.wholesaleForm').css('display', 'none');
});// JavaScript Document

// Clear input text and darken color on a form field
function clearAndColor(el, e2) {
	//grab the current fields value and set a variable
	if (el.defaultValue==el.value) el.value = "";
	//Change the form fields text color
	if (el.style) el.style.color = "#333";

}
//Replace the default text
function reText(el){
	//Change the form fields text color
	if (el.style) el.style.color = "#ccc";
	if (el.value== "") el.value = el.defaultValue;
}

//Get everything started
$j(document).ready(function()
{
	//alert('DOM is ready');
	toad_menu(); //improves the css dropdown menu with animation and ie6 compatibility
	get_cartCount();//get cart count
	get_cartInfo();//get cart info
	get_loginSession();//get session
});

//---------------------------------------------------------------------------------------------
// Shopping cart ajax funcitons
//---------------------------------------------------------------------------------------------
//Go grab the cart count so we can show it on front end
function get_cartCount(){
	//alert('running get cart count');
	$j.ajax({
		type: "GET",
  		url: "/store/cartNum.php",
		async: false,
  		dataType: "html",
		success: function(msg){
     		//alert( "Data Saved: " + msg );
			if(msg == "" || msg == "NULL"){
				$j("#cartCount a").append("<span>My Cart</span>");
			}else{
				$j("#cartCount a").append("<span>"+msg+"</span>");
				//$j("#cartCount").after('<li id="cartCount"><a href="/store/checkout/cart/" class="cart"><span>My Cart</span></a></li>').remove();
			}
			$j("#cartCount a span").css({display: "none"});
			$j("#cartCount a span").animate({ opacity: "show" }, "slow");
		},
		error:function(msg){
     		//alert( "Cart Data Connection Error: " + msg );
			$j("#cartCount a").animate({ opacity: "hide" }, "slow");
		}
		
		});
}

function get_cartInfo(){
	//alert('running get cart count');
	$j.ajax({
		type: "GET",
  		url: "/store/cartInfo.php",
		async: false,
  		dataType: "html",
		success: function(msg){
     		//alert( "Data Saved: " + msg );
			if(msg == "" || msg == "NULL"){
				$j("#cartDisplay").after('').remove();
			}else{
				$j("#cartDisplay").after('<div id="cartDisplay" style="display:none;">'+msg+'</div>').remove();
			}
		},
		error:function(msg){
     		//alert( "Cart Data Connection Error: " + msg );
			$j("#cartDisplay").animate({ opacity: "hide" }, "slow");
		}
		
		});
}

//Go grab the loggin session so we can show it on front end
function get_loginSession(){
	//alert('running get cart count');
	$j.ajax({
		type: "GET",
  		url: "/store/userLoginSession.php",
		async: false,
  		dataType: "html",
		success: function(msg){
     		//alert( "Data Saved: " + msg );
			if(msg == "0" || msg == "" || msg == "NULL"){
				$j("#userLogin").after('<li id="userLogin"><a href="/store/customer/account/" class="tip" title="Click to Log in"><span>Log In</span></a></li>').remove();
			}else{
				$j("#userLogin").after('<li id="userLogin"><a href="/store/customer/account/logout/" class="logout" title="Click to Log out"><span>Log Out</span></a></li>').remove();
			}
			$j("#userLogin a span").css({display: "none"});
			$j("#userLogin a span").animate({ opacity: "show" }, "slow");
		},
		error:function(msg){
     		//alert( "Cart Data Connection Error: " + msg );
			$j("#cartCount a").animate({ opacity: "hide" }, "slow");
		}
		
		});
}

//success function				
function loading(responseText, statusText){
	$j("#contentLoading").animate({ opacity: "show" }, "slow");
	//alert('showResponse() Was Called!');
}
$j().ajaxSend(function(r,s){
	$j("#contentLoading").animate({ opacity: "show" }, "slow");
});

$j().ajaxStop(function(r,s){
	$j("#contentLoading").animate({ opacity: "hide" }, "slow");
});
	
//---------------------------------------------------------------------------------------------
//drop down menus
//---------------------------------------------------------------------------------------------

function toad_menu()
{
		$j(".navigation a, #nav a").removeAttr('title');
		$j(".navigation ul, #nav ul").css({display: "none"}); // Opera Fix
		
		$j(".navigation li, #nav li").hover(function()
		{
			$j(this).find('ul:first').css({visibility: "visible",display: "none"}).slideDown(400,"easeInOutQuart");
		}
		,function()
		{
			$j(this).find('ul:first').css({visibility: "hidden"});
		});
		
}


//---------------------------------------------------------------------------------------------
//tooltips
//---------------------------------------------------------------------------------------------

//Search bar buttons
//---------------------------------------------------------------------------------------------
$j('a#casebutton').qtip({
   content: 'Do i have a case? Fill out our general intake form to find out.',
   show: 'mouseover',
   hide: 'mouseout',
   style: { name: 'cream', tip: true },
   position: {
      corner: {
         target: 'mouse',
         tooltip: 'bottomLeft'
      }
   }
});

$j('a#insbutton').qtip({
   content: 'Resources on how to handle your insurance law case from the insurance law team',
   show: 'mouseover',
   hide: 'mouseout',
   style: { name: 'cream', tip: true },
   position: {
      corner: {
         target: 'mouse',
         tooltip: 'bottomLeft'
      }
   }
});

$j('a#helpartbutton').qtip({
   content: 'Read helpful articles written to aid in your decisions',
   show: 'mouseover',
   hide: 'mouseout',
   style: { name: 'cream', tip: true },
   position: {
      corner: {
         target: 'mouse',
         tooltip: 'bottomLeft'
      }
   }
});

//Help button
$j('a#needhelp').qtip({
   content: 'Click to Reveal Help Options',
   show: 'mouseover',
   hide: 'mouseout',
   style: { name: 'cream', tip: true },
   position: {
      corner: {
         target: 'bottomRight',
         tooltip: 'topRight'
      }
   }
});

//Replace all titles that have class "tip" with qtips
$j('a.tip[title]').qtip({ 
						
	style: { name: 'blue', tip: true },
	position: {
    	corner: {
       		target: 'rightTop',
         	tooltip: 'bottomRight'
    	}
   } 
})
// end tooltips --------------------------------------------------------------------------------

$j(function(){
	//$j('input[name=alias]:radio').focus(function(){$j('div.formOptionNames').slideToggle();return false;alert('Radio Box Selected');});
	//$j('div.formOptionNames').css('display', 'none');
});// JavaScript Document