// JavaScript Document
//#########################
// Dropdown Menu
//#########################
function clickedSurveyButton(smb){
	if(smb){
		try{
			window.keynoteConnectorWindow='primary';
		}
		catch(e){}
		var pn;
		if (typeof(s.pageName)!== 'undefined')
			pn=s.pageName;
		else if (typeof(s_pageName)!== 'undefined')
			pn=s_pageName;
		else pn="Unknown";
		var url='/global/popups/floatingFeedback.html?refpage='+pn+'&smb=true';
		popup=window.open(url,'','resizable=yes,menubar=no,scrollbars=no,toolbar=no,height=450,width=480,left='+(screen.availWidth/2-150)+',top='+(screen.availHeight/2-150));
		if(!popup.opener)popup.opener=window;
		if(popup)popup.focus();
	}
}

$(document).ready(function(){
	$('div.sbr_navigation ul li').hover(
		function() { $('ul', this).fadeIn("fast"); },
		function() { $('ul', this).fadeOut("fast"); 
	});
	
	$('ul.js_homeNav li').hover(
		function() { $('ul', this).toggle("fast"); },
		function() { $('ul', this).toggle("fast"); 
	});
});
//#########################
// The Cookie maker
//#########################
function getCookie(c_name) {
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
		{
		c_start=c_start + c_name.length+1;
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
		}
	  }
	return "";
}


//##########################################
// Client IP location sniffer
//##########################################
var vState="";
//######
// Call to the JSON location data
//######
function getState(){
	script = document.createElement('script')
	script.src = 'http://www.ipinfodb.com/ip_query.php?output=json&callback=initialize'
	document.body.appendChild(script)
}
/**
this pulls the location from the IP and applies it to the interface  
**/
function initialize(obj){
	checkStateCookie()
	$('span.sbr_address').html(window.state);
}


/*******************************************************
this sets the cookie... pulls the location from the selection applies it to the interface  
********************************************************/
function setState(newState) {
	var cState = $.cookieJar('cState');
	//Sets the cookie
	cState.set('state', newState);
	/*cState=getCookie('state');*/
  	window.state = vState ;
	var stateList=new Array('Washington','Oregon','Idaho','Montana','Wyoming','Utah','Colorado','Arizona','New Mexico','North Dakota','South Dakota','Nebraska','Iowa','Minnesota');
	$('span.sbr_address').html(cState.get('state'));
	$(this).bind("change", tb_remove());
	$(this).bind("click", tb_remove());
	for(var i=0; i<stateList.length; i++){
		if(stateList[i]==newState){
			var loc=location.pathname;
			if(loc.indexOf('/out_of_region')!=-1){
				window.location='/smallbusiness/internet/';
			}else{
				window.location.reload();
			}
			return true;
		}
	}
	//not found
	window.location="/smallbusiness/out_of_region/";

	
}

//######
// Check for the any existing state cookies and applies the value to window.state
//######
function checkStateCookie() {
	var cState = $.cookieJar('cState');
	if (cState=="{}") {
		$("a.statemodal").trigger('click');
	};
	vState=cState.get('state');
	if (vState!=null && vState!="") {
		window.state = vState ;
	}
}

//##########################################
// Modal window
//##########################################
$(document).ready(function() {
	getState()
	
//##########################################						   
// expand and collapse shopping cart widget
//##########################################

	//$('.sbr_cart_summary_information table').hide();
	  
	$('.sbr_item_open').toggle(
		function(){
		$(this).css("background", "url(/smallbusiness/images/button-images/cart_expand.gif) left -12px no-repeat");
		$(this).parents('div.sbr_cart_summary_information').find('table').fadeIn(500);
		},
		function(){
		$(this).css("background", "url(/smallbusiness/images/button-images/cart_expand.gif) left top no-repeat")
		$(this).parents('div.sbr_cart_summary_information').find('table').fadeOut(500);
		}
	);
	
//##########################################
// expand and collapse product detail widget
//##########################################

   $(".sbr_more").click(function(){
     $(this).toggle();
	 $(this).next(".sbr_close").toggle();
	 $(this).parent().find(".sbr_more_info").fadeIn(500);
   });
   $(".sbr_close").click(function(){
     $(this).toggle();
	 $(this).prev(".sbr_more").toggle();
	 $(this).parent().find(".sbr_more_info").fadeOut(500);
   });
   
   $(".sbr_more").click(function(){
     $(this).fadeOut(1);
	 $(this).next(".sbr_close").fadeIn(1);
	 $(this).parent().find(".sbr_more_content").fadeIn(500);
   });
   $(".sbr_close").click(function(){
     $(this).fadeOut(1);
	 $(this).prev(".sbr_more").fadeIn(1);
	 $(this).parent().find(".sbr_more_content").fadeOut(500);
   });
   
   /* open/close functionality for the h2 with the link - wrapped in a new class */   
   $(".sbr_more_h2").click(function(){
     $(this).fadeOut(1);
	 $(this).next(".sbr_close_h2").fadeIn(1);
	 $(this).parent().find(".sbr_more_content").fadeIn(500);
   });
   $(".sbr_close_h2").click(function(){
     $(this).fadeOut(1);
	 $(this).prev(".sbr_more_h2").fadeIn(1);
	 $(this).parent().find(".sbr_more_content").fadeOut(500);
   });
   
   
   $("div.sbr_radio_option").find(".sbr_more").click(function(){
     $(this).toggle();
	 $(this).next(".sbr_close").toggle();
	 $(this).parent().next(".sbr_more_info").fadeIn(500);
   });
   $("div.sbr_radio_option").find(".sbr_close").click(function(){
     $(this).toggle();
	 $(this).prev(".sbr_more").toggle();
	 $(this).parent().next(".sbr_more_info").fadeOut(500);
   });
   

// expand and collapse shopping cart widget

   $("tr.sbr_product_no").find(".sbr_more").click(function(){
     $(this).toggle();
	 $(this).next(".sbr_close").toggle();
	 $(this).parent().parent().next().find("table").fadeIn(500);
   });
   $("tr.sbr_product_no").find(".sbr_close").click(function(){
     $(this).toggle();
	 $(this).prev(".sbr_more").toggle();
	 $(this).parent().parent().next().find("table").fadeOut(500);
   });
   
// expand and collapse product detail widget

   $("div.sbr_radio_option").find(".sbr_more").click(function(){
     $(this).toggle();
	 $(this).next(".sbr_close").toggle();
	 $(this).parent().next(".sbr_more_info").fadeIn(500);
   });
   $("div.sbr_radio_option").find(".sbr_close").click(function(){
     $(this).toggle();
	 $(this).prev(".sbr_more").toggle();
	 $(this).parent().next(".sbr_more_info").fadeOut(500);
   });
   


// expand and collapse product + detail shop large detail widget

   $("div.sbr_radio_option2").find(".sbr_more2").click(function(){
     $(this).toggle();
	 $(this).next(".sbr_close2").toggle();
	 $(this).parent().next(".sbr_more_info2").fadeIn(500);
   });
   $("div.sbr_radio_option2").find(".sbr_close2").click(function(){
     $(this).toggle();
	 $(this).prev(".sbr_more2").toggle();
	 $(this).parent().next(".sbr_more_info2").fadeOut(500);
   });
   


// expand and collapse product + detail shop large detail widget more info 3 

   $("div.sbr_radio_option3").find(".sbr_more3").click(function(){
     $(this).toggle();
	 $(this).next(".sbr_close3").toggle();
	 $(this).parent().next(".sbr_more_info3").fadeIn(500);
   });
   $("div.sbr_radio_option3").find(".sbr_close3").click(function(){
     $(this).toggle();
	 $(this).prev(".sbr_more3").toggle();
	 $(this).parent().next(".sbr_more_info3").fadeOut(500);
   });
 });

//Check Box Limiter
//initial checkCount of zero
var checkCount=0

//maximum number of allowed checked boxes
var maxChecks=3

function setChecks(obj, maxChecks){
//increment/decrement checkCount
if(obj.checked){
checkCount=checkCount+1
}else{
checkCount=checkCount-1
}
//if they checked a too many boxes, uncheck a box, then decrement checkcount and pop alert
if (checkCount>maxChecks){
obj.checked=false
checkCount=checkCount-1
alert('you may only choose up to '+maxChecks+' options')
}
}
//-->



//#########################
// Detail Panel 
//#########################
$(document).ready(function(){
	$("a.js_description").addClass("js_active");
	$("div.js_detail_description").toggle();					   
						   
   $("a.js_description").click(function(){
	$("ul.sbr_detail_tabs a").removeClass("js_active");
	$(this).addClass("js_active");
	$("div.js_detail").hide(); 
	$("div.js_detail_description").show( );	
	return false;
   });
   			   
   $("a.js_features").click(function(){
	$("ul.sbr_detail_tabs a").removeClass("js_active");
	$(this).addClass("js_active");
	$("div.js_detail").hide(); 
	$("div.js_detail_features").show( );	
	return false;
   });
   			   
   $("a.js_related_links").click(function(){	  
	$("ul.sbr_detail_tabs a").removeClass("js_active");
	$(this).addClass("js_active");
	$("div.js_detail").hide(); 
	$("div.js_detail_related_links").show( );	
	return false;
   });
 });


// Fix IE from dropping Cleartype rendering on 
// faded elements.  For full explanation, see
// http://blog.bmn.name/2008/03/jquery-fadeinfadeout-ie-cleartype-glitch/
(function($) {
	$.fn.customFadeTo = function(speed, opacity, callback) {
		$(this).fadeTo(speed, opacity, function() {
			if((!jQuery.support.opacity) && (opacity == 1))  {
				$(this).get(0).style.removeAttribute('filter');
			}
			if(callback != undefined)
				callback();
			});
		};
	})(jQuery);

// Adds a fadeIn-onmouseover, fadeOut-onmouseout 
function AddFadeMouseEvent(strClass) {
    $(strClass).hover(
        function() {
        	// On load, first column is faded in.  This will fade it out
        	// if the first column you mouse over is a different column.
        	$("#switchme-0 .col-top").each(function(){
        		if ((!$(this).hasClass(strClass)) && ($(this).css("opacity") > 0.5)) {
        			$(this).customFadeTo(200, 0.5);
        		}
        	});
        	if ($(this).css("opacity") < 1) {
                $(strClass).customFadeTo(200, 1.0);
        	}
        },
        function() {
            $(strClass).customFadeTo(200, 0.5);
			//fade col0 back in when another column is moused out
			$(".col0").customFadeTo(0,1.0);
        }
    )
    AddClickHandler(strClass);
}

function AddClickHandler(strClass) {
    $(strClass).click(function() {
    	var strUrl = $(this).find("a").attr("href");
    	document.location=strUrl;
    });

}
function track6(qLinkName)
{
	var s=s_gi(s_account);s.templtv=s.linkTrackVars;s.templte=s.linkTrackEvents;s.linkTrackVars='eVar6';s.eVar6=qLinkName;s.tl(this,'o',qLinkName);if(s.templtv)s.linkTrackVars=s.templtv;if(s.templte)s.linkTrackEvents=s.templte;
}

function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (
aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
} 

