// embed flash movies
var flashvars = {
	xmlLocation: 'assets/flash/TopSeller_XML.aspx',
	frontThumbNumber: '0'
};
var params = {
	wmode: 'transparent'
};
var attributes = {};
swfobject.embedSWF('assets/flash/CarouselDesignerV4.swf', 'flash-content', '381', '291', '9.0.0', 'assets/flash/expressInstall.swf', flashvars, params, attributes);

// run jquery scripts onload
$(function(){
	
	// set external links
	$('a[rel=external]').attr('target', '_blank');
	
	// set nav padding for double lines
	$('ul.main-nav li a:has(br)').addClass('double');
	
	
	// set global search box
	$('input.quick-search-query').focus(function(){
	//	alert($(this).attr('value'));
		$(this).attr('value', '');
	});
	
	// rollovers on quick links
	$('ul.quick-links > li').hover(function(){

		$(this).toggleClass('hover');

	},function(){

		$(this).toggleClass('hover');
	});
	
	
	// add quotes to quoted elements
	/*
	$('div.promo-box q, q.big-quote').each(function(){
		var open_quote = $('<span class="quotes-open"><img src="assets/img/quotes-open.png" alt="" width="18" height="13" /></span>');
		var close_quote = $('<span class="quotes-close"><img src="assets/img/quotes-close.png" alt="" width="18" height="13" /></span>');
		$(this).prepend(open_quote);
		$(this).append(close_quote);
	});
	*/
	
	// scripted questions
	$('div.question-list p:gt(0).circle-arrow a').css('display', 'block');
	$('div.question-list p:gt(0)').css('display', 'none');
	$('div.questions-next p.circle-arrow a').css('visibility', 'visible');
	var num_questions = $('div.question-list p').size();
	var current_question = 0;
	var next_question;
	$('div.questions-next a').click(function(){
		// find the next question and move it into position
		next_question = current_question + 1;
		if(next_question >= num_questions) next_question = 0;
		
		// slide them into place
		$('div.question-list p:eq(' + next_question + ')')
			.css({'left': '230px', 'display': 'block'})
			.animate({'left': '10px'}, 500);
		$('div.question-list p:eq(' + current_question + ')')
			.animate({'left': '-220px'}, 500);
			
		// increment the question counter
		current_question++;
		if(current_question >= num_questions) current_question = 0;
		
		// disable the link
		return false;
	});
	
});

// currency links
	window.onload = function()	{
		//opera pad
		if( navigator.userAgent.match( /opera/i ) )	{
			$( 'form.quick-search input.quick-search-query' ).css( 'padding-top', '1px' );
			$( 'form.quick-search input.quick-search-query' ).css( 'height', '24px' );
		}
		
		//NOTE: THIS IS WORK IN PROGRESS - DEBUGGIN
		var li	= $( 'li.currencychange' )[0];
		$( li ).css( 'display', 'block' );
		var currencyHide	= function() { 
			$( 'ul#currencylist' ).css( 'display', 'none');
			$( 'ul#account-links li.currencychange a.currency' ).css('color', '#fff');
			//var li	= $( 'li.currencychange' )[0];
			//li.onmouseover	= currencyShow;
		}
		var currencyShow	= function() {
			$( 'ul', this ).css( 'display', 'block' );
			$( 'ul#account-links li.currencychange a.currency' ).css('color', '#00b7f1');
			
			/**
			li.onmouseover	= null;
			$( this ).css( 'border', '1px solid red' ); 
		
			//cannot detect height of ul - must add height of individual lis instead
			var lis	= $( 'li', this );
			var h0	=  $( this ).outerHeight();
			for( var i=0,i2=lis.length; i<i2; i++ )	{
				h0	+= $( lis[i] ).outerHeight();
			}
			
			$( "body" ).append(
				$( "<div/>" )
					.attr( "id", "hitArea" )
					.css( "position", "absolute" )
					.css( "border",	'1px solid green' )
					.css( "width",		$( this ).outerWidth() - $( 'li', this ).outerWidth() )
					.css( "height",		h0 )
					.css( "top",		$( this ).offset().top )
					.css( "left",		$( this ).offset().left )
					.append(
						$( "<a/>" )
							.attr( "href", "#" )
					)
			);
			$( '#hitArea' ).attr( 'onmouseover', currencyHide );
			*/
			
		}
		
		li.onmouseout	= currencyHide;
		li.onmouseover	= currencyShow;
		document.getElementById('currencylist').style.display = 'none';
		
		var lis2 = document.getElementById('currencylist').getElementsByTagName('li');
		for(i = 0; i < lis2.length; i++)
		{
			var li = lis2[i];
			if (li.className == 'currency1')
			{
				li.style.right='-12px';
			}
			if (li.className == 'currency2')
			{
				li.style.right='-12px';
				li.style.top='34px';
			}
			if (li.className == 'currency3')
			{
				li.style.right='-12px';
				li.style.top='63px';
			}
		}
	}





function search_OnClick(MainSearch){

   objField    = document.getElementById(MainSearch);

   objOrigText = document.getElementById("OrigSearchText");

   if (trim(objField.value) == trim(objOrigText.value)) {

      objField.value = "";

   }

   return;

}



function search_OnBlur(MainSearch){

   objField    = document.getElementById(MainSearch);

   objOrigText = document.getElementById("OrigSearchText");



   if (trim(objField.value) == "") {

      objField.value = objOrigText.value;

   }

   return;

}


// Removes leading and trailing spaces from the passed string. Also removes
// consecutive spaces and replaces it with one space. If something besides
// a string is passed in (null, custom object, etc.) then return the input.
// this function is needed for the Main Site Search retention of value to work.
function trim(inputString) {
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
       
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
       
   ch = retValue.substring(retValue.length-1, retValue.length);
       
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }

   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
       
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function addToFavorites() { 
        sURLaddress = window.location.toString()
          if (window.external) { 
            window.external.AddFavorite(sURLaddress,document.title) 
        } else { 
            alert("Sorry! Your browser doesn't support this function."); 
        } 
    }     

