jQuery(document).ready(function($){


// ----------------------------------------------------------------------------------------
// START Printer Compatibility
// ----------------------------------------------------------------------------------------

//	if ( $('div.block-layered-nav dd.ddPrinter-Compatibility').length ) {
		// create CTA.
//		$('div.block-layered-nav dt.dtPrinter-Compatibility').append('<div id="rollOverCTA">Roll over for list</div>');
		// get the list items.
//		var tempPrinterCompatibilityList = $('div.block-layered-nav dd.ddPrinter-Compatibility ol').html();
		// kill original list items.
//		$('div.block-layered-nav dd.ddPrinter-Compatibility ol').remove();
		// build custom list within custom div.
//		var printerCompatibilityList = "<div id='printerCompatibilityMask'><img src='/skin/frontend/discountid/did_theme_two/images/spacer.gif' width='1000' height='" + $(document).height() + "' border='0' /></div><div id='printerCompatibilityLabel'>" + $('div.block-layered-nav dt.dtPrinter-Compatibility').html() + "</div><div id='printerCompatibilityList'><ul>" + tempPrinterCompatibilityList + "</ul></div>";
//		$('div.main').append(printerCompatibilityList);
		// position the overlay.
/*		var dtPrinter_Compatibility = $('div.block-layered-nav dt.dtPrinter-Compatibility').offset();
		var flyoutLeftBuffer = dtPrinter_Compatibility.left - 17;
		var listLeft = 200 + flyoutLeftBuffer;
		var listTop = parseFloat(dtPrinter_Compatibility.top);
		var labelLeft = flyoutLeftBuffer;
		var labelTop = listTop;
*/		
	//	if ( $.browser.msie && (parseFloat($.browser.version)) == 7 ) {
	//		listTop = parseFloat(dtPrinter_Compatibility.top) - 201;
	//		labelTop = listTop;
	//	}
	//	if ( $.browser.msie && (parseFloat($.browser.version)) == 6 ) {
	//		listTop = parseFloat(dtPrinter_Compatibility.top) - 247;
	//		labelTop = listTop;
	//	}
	
/*		$('#printerCompatibilityMask').css('height', $(document).height() );
	
		$('#printerCompatibilityLabel').css({'left':labelLeft,'top':labelTop});
		$('#printerCompatibilityList').css({'left':listLeft,'top':listTop});
		
		$('div.block-layered-nav dt.dtPrinter-Compatibility').mouseenter( function() { 
			$('#printerCompatibilityLabel, #printerCompatibilityList, #printerCompatibilityMask').show();
		});
		
		$('#printerCompatibilityMask').mouseover( function() { 
			$('#printerCompatibilityLabel, #printerCompatibilityList, #printerCompatibilityMask').hide();
		});
		
	} */	// end if




// ----------------------------------------------------------------------------------------
// END Printer Compatibility
// ----------------------------------------------------------------------------------------


// ----------------------------------------------------------------------------------------
// START double price solution
// ----------------------------------------------------------------------------------------

	$('div.product-options-bottom div.price-box').hide();

// ----------------------------------------------------------------------------------------
// END double price solution
// ----------------------------------------------------------------------------------------





	
// ----------------------------------------------------------------------------------------
// START product page grid equalizer
// ----------------------------------------------------------------------------------------
	$('div.category-view div.category-products ul.products-grid').each(function(){
		var productnameHeight = 0;
		var productModelHeight = 0;
		var priceboxHeight = 0;
		
		$('li', this).each(function(){
			if (productnameHeight < $('h2.product-name', this).height()) { productnameHeight = $('h2.product-name', this).height(); }
			if (productModelHeight < $('div.productModel', this).height()) { productModelHeight = $('div.productModel', this).height(); }
			if (priceboxHeight < $('div.price-box', this).height()) { priceboxHeight = $('div.price-box', this).height(); }
		});
		$('li h2.product-name', this).height(productnameHeight);
		$('li div.productModel', this).height(productModelHeight);
		$('li div.price-box', this).height(priceboxHeight);
	});
// ----------------------------------------------------------------------------------------
// END product page grid equalizer
// ----------------------------------------------------------------------------------------


	
	
	
	
	
	
	
// ----------------------------------------------------------------------------------------
// START product page equalizer
// ----------------------------------------------------------------------------------------
//	$(window).load(function(){
		if ( $('div.product-view div.product-collateral').length && $('div.product-view div.productRightCol').length ) {
//			$('div.product-view div.tab-content img').live('load',function(){
				var theProductCollateralHeight = $('div.product-collateral').height();
//				var theProductCollateralproductTabsOverviewHeight = $('div.product-collateral').height();
				var theProductRightHeight = $('div.productRightCol').height();
//				alert( $('div.product-view div.product-collateral div.productTabsOverview').height() );
				if ( theProductCollateralHeight < theProductRightHeight ) {
					$('div.ui-tabs-panel').height(theProductRightHeight - 2+'px');
				}
		}

// ----------------------------------------------------------------------------------------
// END product page equalizer
// ----------------------------------------------------------------------------------------


// ----------------------------------------------------------------------------------------
// START cart page equalizer
// ----------------------------------------------------------------------------------------
	var cartleftColHeight = $('cart-collaterals div.crosssell').height();
	var cartcenterColHeight = $('div.cartCodes').height();
	var cartrightColHeight = $('div.totals').height();
	var isdoubled = false;
	if ($('div.cartHolder div.crosssell').length) {
		if (cartleftColHeight > cartrightColHeight) {
			$('div.totals').height(cartleftColHeight -28);
			isdoubled = true;
		}
		if (cartcenterColHeight > cartleftColHeight) {
			$('div.totals').height(cartcenterColHeight -28);
			isdoubled = true;
		}
	} else {
		if (cartcenterColHeight > cartrightColHeight) {
			$('div.totals').height(cartcenterColHeight -1);
			isdoubled = true;
		}
	}
	
	if (isdoubled && $.browser.msie && $.browser.version.substr(0,1)<8) {
		$('div.totals').height( $('div.totals').height() / 2 );
	}
	
// ----------------------------------------------------------------------------------------
// END cart page equalizer
// ----------------------------------------------------------------------------------------



// ----------------------------------------------------------------------------------------
// START Checkout
// ----------------------------------------------------------------------------------------
	// when the onepage checkout starts, IE7 needs this to properly render the layout. IE7 render glitch.
	if ( $('#login-email').length ) {
		$('#login-email').focus();
	}
	if ( $('#email').length ) {
		$('#email').focus();
	}
	
	if ( $('.checkout-onepage-success ul.homeCategories').length ) {
		$('.checkout-onepage-success ul.homeCategories').css({"margin-left":"15px"});
	}
// ----------------------------------------------------------------------------------------
// END Checkout
// ----------------------------------------------------------------------------------------



// ----------------------------------------------------------------------------------------
// START CMS page column level
// ----------------------------------------------------------------------------------------
	if ( $('.cms-page-view div.col2-left-layout').length ) {
		var cmsHeight = $('div.col-main').height();
		var cmsLeftHeight = $('div.col-left').height();
		if ( cmsHeight > cmsLeftHeight ) { 
			$('div.col-left').height( cmsHeight+20 );
		}
	}
// ----------------------------------------------------------------------------------------
// END Checkout
// ----------------------------------------------------------------------------------------


//});





//------------------------------------------------------------------------------------------------------
//  START jquery based loginForPrice.
//	all elements specified in the init will trigger a login overlay form
//------------------------------------------------------------------------------------------------------
	function loginForPriceHeader_init(effectedElements){
		
		$(effectedElements).hover(
			function(){
				// over
				var p = $("div.quick-access");
				var offset = p.offset();
				var theWidth = p.width();
				var theHeight = p.height();
				
				if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // not IE6
					$('#headerLoggedOutListLogIn').hide();
				} else {
					$('#headerLoggedOutListLogIn a').css({'color':'#fff'});
				}
				
				$('#loginForPrice_header').css({'top':offset.top+theHeight+13+'px','left':offset.left+17+'px'});
				$('#loginForPrice_header').show();
			},function(){
				// exit
			}
		); 
	}


	function loginForPrice_init(effectedElements){
		$(effectedElements).click(function(){
			
			var pageWidth = $(document).width();
			var pageHeight = $(document).height();
			var viewportWidth = $(window).width();
			var viewportHeight = $(window).height();

			$('#loginForPrice_overlay').css({'width':pageWidth+'px','height':pageHeight+'px'});
			$('#loginForPrice_window').center();
			
			$('#loginForPrice_overlay').fadeTo(500,0.75);
			$('#loginForPrice_window').fadeIn(500);
			$("#loginForPrice_overlay, #loginForPrice_overlayClose").click(loginForPrice_remove);
			this.blur();
			return false;
		});
	}

	function loginForPrice_remove() {
		$("#loginForPrice_overlay, #loginForPrice_window").fadeOut();
		return false;
	}
	
	jQuery.fn.center = function () {
//  this.css("position","absolute");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
	}



if ( $('ul#headerLoggedOutList').length ) {

	var refererString = $('#headerLoggedOutList #headerLoggedOutListLogIn a').attr('href');
	var refererStringArray = refererString.split('/');
	var refererStringID = refererStringArray[refererStringArray.length-2];


//jQuery(document).ready(function($){
	
	// create floating login content
	
	var login_form_floating = '<style>';
	login_form_floating = login_form_floating + '		#loginForPrice_overlay { background:#000; display:none; position:absolute; top:0; left:0; z-index:150; }';
	login_form_floating = login_form_floating + '		#loginForPrice_window { padding-top:15px; width:270px; height:150px; border:1px solid #a0a0a0; background:#fff; display:none; text-align:left; position:absolute; top:0; left:0; z-index:151; }';
	login_form_floating = login_form_floating + '		#loginForPrice_window #loginForPrice_overlayClose { background:url(/skin/frontend/discountid/did_theme_three/images/cart/overlayLoginCloseBtn.gif); width:49px; height:12px; position:absolute; top:2px; right:5px; z-index:152; cursor:pointer; }';
	login_form_floating = login_form_floating + '		#loginForPrice_window button.button { margin-top:10px; }';
	login_form_floating = login_form_floating + '		#loginForPrice_window label { margin:5px 0 0 20px; float:left; }';
	login_form_floating = login_form_floating + '		#loginForPrice_window div.input-box { margin:0 0 0 20px; }';
	login_form_floating = login_form_floating + '		#loginForPrice_window div.input-box input { width:200px; }';
	login_form_floating = login_form_floating + '		#loginForPrice_window #buttonAreaOverlay { margin:0 0 0 20px; width:206px; }';
	login_form_floating = login_form_floating + '		#loginForPrice_window #overlayForgotPasswordLink { margin:10px 0 0 55px; }';
	login_form_floating = login_form_floating + '		#loginForPrice_window #newCustomerCopy { margin:0 10px 0 0; float:right; }';
	login_form_floating = login_form_floating + '		#loginForPrice_window div.buttons-set { width:205px; float:right; margin:15px 0 0 0; }';
	login_form_floating = login_form_floating + '		#loginForPrice_window button#send2 { float:right; background:url(/skin/frontend/discountid/did_theme_three/images/cart/overlayLoginBtn.gif); width:84px; height:15px; }';
	login_form_floating = login_form_floating + '		#loginForPrice_window button#register2 { float:right; background:url(/skin/frontend/discountid/did_theme_three/images/cart/overlayRegisterBtn.gif); width:84px; height:15px; }';
	login_form_floating = login_form_floating + '		#loginForPrice_window div.buttons-set button.button { float:right; margin:0; }';
	login_form_floating = login_form_floating + '</style>';
	login_form_floating = login_form_floating + '<form action=\"/customer/account/loginPost/referer/'+refererStringID+'/\" method=\"post\" id=\"login-form-floating\">';
	login_form_floating = login_form_floating + '	<div id="loginForPrice_overlayClose"></div>';
	login_form_floating = login_form_floating + '	<div><label for=\"email\" class=\"required\">Email Address</label>';
	login_form_floating = login_form_floating + '  <div class=\"input-box\"><input name=\"login[username]\" tabindex=\"5\" value=\"\" id=\"email\" type=\"text\" class=\"input-text required-entry validate-email\" title=\"Email Address\" /></div></div>';
	login_form_floating = login_form_floating + '	<div><label for=\"pass\" class=\"required\">Password <a href=\"/customer/account/forgotpassword/\" id="overlayForgotPasswordLink">Forgot Password?</a></label>';
	login_form_floating = login_form_floating + '	<div class=\"input-box\"><input name=\"login[password]\" tabindex=\"6\" type=\"password\" class=\"input-text required-entry validate-password\" id=\"pass\" title=\"Password\" /></div></div>';
	login_form_floating = login_form_floating + ' <div id="buttonAreaOverlay">';
	login_form_floating = login_form_floating + '	<button type=\"submit\" class=\"button\" tabindex=\"7\" name=\"send\" id=\"send2\"></button>';
	login_form_floating = login_form_floating + '	<div class=\"buttons-set\"><button type=\"button\" tabindex=\"4\" id=\"register2\" class=\"button\" onclick=\"window.location=\'/customer/account/create/\';\"></button><span id=\"newCustomerCopy\">New Customer?</span></div></div>';
	login_form_floating = login_form_floating + '</form>';

	$("body").append("<div id='loginForPrice_overlay'></div><div id='loginForPrice_window'>" + login_form_floating + "</div>");

	loginForPrice_init('span.loginForPrice');//pass comma delimited appostrophie wrapped list of elements to apply loginForPrice

	

	
//});

//------------------------------------------------------------------------------------------------------
//  END jquery based loginForPrice.
//------------------------------------------------------------------------------------------------------


//------------------------------------------------------------------------------------------------------
//  START jquery based Header Login Swapper.
//	A mouse over will display a login form.
//------------------------------------------------------------------------------------------------------

//jQuery(document).ready(function($){

	var login_form_header = '<style>'+'\n';
	login_form_header = login_form_header + '	#loginForPrice_header { width:265px; height:60px !important; background-color:#ffffff !important; display:none; position:absolute; top:0; left:0; z-index:151; }'+'\n';
	login_form_header = login_form_header + '	#loginForPrice_header button.button { margin-top:0px; }'+'\n';
	login_form_header = login_form_header + '	#loginForPrice_header #overlayForgotPasswordLink { margin:1px 5px 0 0; width:125px; float:left; display:inline; }'+'\n';
	login_form_header = login_form_header + '	#loginForPrice_header div.inputSpace { display:inline; float:left; margin:0 6px 0 0; background:#fff; text-align:left; width:100px; }'+'\n';
	login_form_header = login_form_header + '	#loginForPrice_header div.inputSpace label { font-size:9px; }'+'\n';
	login_form_header = login_form_header + '	#loginForPrice_header div.inputSpace div.input-boxHeaderPassword { position:relative; }'+'\n';
	login_form_header = login_form_header + '	#loginForPrice_header div.inputSpace div.input-boxHeaderPassword input#passCover { position:absolute; top:0; left:0; z-index:152; }'+'\n';
	login_form_header = login_form_header + '	#loginForPrice_header div.inputSpace div.input-boxHeaderPassword input#pass { position:absolute; top:0; left:0; z-index:151; }'+'\n';
	login_form_header = login_form_header + '	#loginForPrice_header div.inputSpace input.input-text { margin:0; width:93px; height:18px; font-size:10px; }'+'\n';
	login_form_header = login_form_header + '	#loginForPrice_header div.inputSpace input#headerpass { margin:0; width:93px; height:18px; font-size:10px; display:inline; }'+'\n';
	login_form_header = login_form_header + '	#loginForPrice_header div.inputSpace input#passCover { margin:0; width:93px; height:18px; font-size:10px; display:inline; }'+'\n';
	login_form_header = login_form_header + '	#loginForPrice_header div.buttons-set { float:right; margin:0 6px 0 0; background:#fff; clear:none; }'+'\n';
	login_form_header = login_form_header + '	#loginForPrice_header div.buttons-set button.button { float:left; margin:0; }'+'\n';
	login_form_header = login_form_header + '	#loginForPrice_header #overlayForgotPasswordLink { float:left; margin:3px 0 0 0; font-size:9px; text-align:right; width:205px; display:block;}'+'\n';
	login_form_header = login_form_header + '	#loginForPrice_header div.buttons-set button.button { width:47px; height:19px; text-indent:-9999; background:url(/skin/frontend/discountid/did_theme_three/images/cart/headerOverlayLoginBtn.gif) no-repeat 0 0; float:left; margin:2px 0 0 0; }'+'\n';
	login_form_header = login_form_header + '</style>'+'\n';
	login_form_header = login_form_header + '<div style=\"display:block;\">'+'\n';
	login_form_header = login_form_header + '<form action=\"/customer/account/loginPost/referer/'+refererStringID+'/\" method=\"post\" id=\"login-form-header\">'+'\n';
	login_form_header = login_form_header + '	<div class=\"inputSpace\">'+'\n';
	login_form_header = login_form_header + ' 	<div class=\"input-box\"><input name=\"login[username]\" tabindex=\"1\" value=\"Email Address\" id=\"email\" type=\"text\" class=\"input-text required-entry validate-email\" title=\"Email Address\" onblur=\"if(this.value == \'\') { this.value=\'Email Address\'}\" onfocus=\"if (this.value == \'Email Address\') {this.value=\'\'}\" /></div></div>'+'\n';
	login_form_header = login_form_header + '	<div class=\"inputSpace\">'+'\n';
	login_form_header = login_form_header + '	<div class=\"input-box input-boxHeaderPassword\"><input name=\"temploginPass\" type=\"text\" value=\"Password\" class=\"input-text required-entry validate-password\" id=\"passCover\" title=\"Password\" autocomplete=\"off\" /><input name=\"login[password]\" type=\"password\" tabindex=\"2\" value=\"\" class=\"input-text required-entry validate-password\" id=\"headerpass\" title=\"Password\" autocomplete=\"off\" /></div></div>'+'\n';
	login_form_header = login_form_header + '	<div class=\"buttons-set\"><button type=\"submit\" tabindex=\"3\" class=\"button\" name=\"send\" id=\"send2\"></button></div>'+'\n';
	login_form_header = login_form_header + '</form>'+'\n';
	login_form_header = login_form_header + '<div>'+'\n';
	login_form_header = login_form_header + '<a href=\"/customer/account/forgotpassword/\" id="overlayForgotPasswordLink">Forgot Your Password?</a>'+'\n';

	$("body").append("<div id='loginForPrice_header'>" + login_form_header + "</div>");

	loginForPriceHeader_init('#headerLoggedOutListLogIn');//pass comma delimited appostrophie wrapped list of elements to apply loginForPriceHeader

	

	
	
//	function removeheaderOverlay() {
//		if (killHeadOverlay){
//			clearTimeout(killHeadOverlay);
//		} else {
//			killHeadOverlay = setTimeout($('#loginForPrice_header').hide(); , 2000 );
//		}
//	}
	
	
//	$('#passCover').show();
//	$('#pass').hide();

//	$('#headerpass').focus(function() {
//		$('#passCover').hide();
//			setTimeout( function() {
//				$("#headerpass").focus();
//			} , 500);
//	});

	headerpassTriggered = 0;
	$('#passCover, #headerpass').focus(function() {
		headerpassTriggered++;
//		$('#passCover').hide();
		if (headerpassTriggered < 2) {
			$('#passCover').remove();
			setTimeout( function() { $("#headerpass").focus(); } ,500);
		}
	});
	
	
	
//	$('#headerpass').blur(function() {
//		if ($('#headerpass').val() === '') {
//			$('#passCover').blur();
//			$('#passCover').show();
//		}
//	});


//});


}

//------------------------------------------------------------------------------------------------------
//  END jquery based Header Login Swapper.
//	A mouse over will display a login form.
//------------------------------------------------------------------------------------------------------


//------------------------------------------------------------------------------------------------------
//  START login message highlight
//------------------------------------------------------------------------------------------------------
//jQuery(document).ready(function($){
	effectMessage1 = $('div.account-login ul.messages:contains(Account confirmation is required.)');
	effectMessage2 = $('div.account-login ul.messages:contains(This account is not confirmed.)');
//	alert(effectMessage1.length+' '+effectMessage2.length);
	if (effectMessage1.length > 0) {
		effectMessage1.addClass('messagesConfirm1');
	}
	if (effectMessage2.length > 0) {
		effectMessage2.addClass('messagesConfirm2');
	}
//});
//------------------------------------------------------------------------------------------------------
//  END login message highlight
//------------------------------------------------------------------------------------------------------




// ----------------------------------------------------------------------------------------
// START Filter collapse
// ----------------------------------------------------------------------------------------
	var filterItemsToShowCount = 5; // This is the number of filter items per group to collapse down to.
	var filterFadeoutTime = 500;
	var filterFadeinTime = 500;
	var filterIsShortened = false;
	var filterCount = 0;
	var filtersCollapsed = 0;
	var newTempLiCount = 0;
	var leftNavRemoveHeight = 0;
	var isSingleFilter = 0;
	var singleFilterExtraHeight = 0;
	$('div.block-layered-nav:contains(Refine your results) div.block-content dl dd ol').each(function(){
		tempLiCount = $('li', $(this)).length;
			
		if (tempLiCount > filterItemsToShowCount) {
			
			removeHeight();
						
			filterCount++;
			$(this).addClass('shortenedList');
			// There are more than the items allowed to be seen, so hide the rest.
			filterIsShortened = true;
			$('li:gt('+(filterItemsToShowCount-1)+')',$(this)).slideUp(filterFadeoutTime, function() { filtersCollapsed++; });
			$(this).append('<li class="filterNavMoreLink">More</li>');
			
			$('li.filterNavMoreLink', $(this)).click(function(){
				if ( $(this).siblings('li:hidden').length > 0 ) {
					
					singleFilterExtraHeight = $(this).siblings('li:hidden').length * 16;
					runningHeight += singleFilterExtraHeight;
					isSingleFilter = 1;
					addHeightGoColumnEqualizer(isSingleFilter);
					
					$(this).siblings('li:hidden').slideDown(filterFadeinTime*$(this).length, function(){ /*goColumnEqualizer();*/ });
					$(this).html('Less');
				} else {
					
									
					var temp = $(this).siblings('li').length - 5;
					singleFilterExtraHeight = temp * 16;
					runningHeight -= singleFilterExtraHeight;
					isSingleFilter = 1;
					goColumnEqualizer(isSingleFilter);
					
					$(this).siblings('li:gt('+(filterItemsToShowCount-1)+')').slideUp(filterFadeoutTime*$(this).length, function(){ /*goColumnEqualizer();*/ });
					$(this).html('More');
				}
			});
			
		}
	});
		
	
	$('li.filterNavMoreLink').css({'cursor':'pointer','color':'#440008','text-decoration':'underline'});
	
	if (filterIsShortened) {
		$('div.block-layered-nav:contains(Refine your results) div.block-content').before('<div id="filterNavShowAll" style="display:none;">Show all filters</div>');
		$('#filterNavShowAll').css({'margin':'3px 0 3px 15px','cursor':'pointer','color':'#440008','font-style':'italic'}).show().click(function(){
			
			
			if ( $('div.block-layered-nav:contains(Refine your results) div.block-content dl dd ol.shortenedList li:hidden').length > 0 ) {
				// There are hidden filter items, so trigger show all.
				runningHeight = originalHeightLeft;
				
				$('div.block-layered-nav:contains(Refine your results) div.block-content dl dd ol.shortenedList').each(function(){
					
					$('li:hidden', $(this)).slideDown(filterFadeinTime*$(this).length, function(){ /*goColumnEqualizer();*/ });
					$('li.filterNavMoreLink', $(this)).html('Less');
				});
				$(this).html('Hide some of the filters');
				isSingleFilter = 2;
				addHeightGoColumnEqualizer(isSingleFilter);

			} else {
				
				runningHeight = originalHeightLeft - leftNavRemoveHeight;
				
				// There are no hidden filter items, so trigger hide all.
				$('div.block-layered-nav:contains(Refine your results) div.block-content dl dd ol.shortenedList').each(function(){
					$('li:gt('+(filterItemsToShowCount-1)+')',$(this)).not('.filterNavMoreLink').slideUp(filterFadeoutTime*$(this).length, function() { /*goColumnEqualizer();*/ });
					$('li.filterNavMoreLink', $(this)).html('More');
				});
				$(this).html('Show all filters');
				isSingleFilter = 2;
				goColumnEqualizer(isSingleFilter);

			}
		});
	}
	
	function removeHeight() {
		
		newTempLiCount = tempLiCount - 5;
		  var i;
		  
		  for(i = 0; i < newTempLiCount; i++){
			  leftNavRemoveHeight += 16;
		  }
		
	}

// ----------------------------------------------------------------------------------------
// END Filter collapse
// ----------------------------------------------------------------------------------------

// ----------------------------------------------------------------------------------------
// START Column equalizer
// ----------------------------------------------------------------------------------------
//function categoryColumnEqualizer() {
	//var hasOriginalHeights = false;
	
	var originalHeightLeft = 0;
	$('body.catalog-category-view div.col-left div.block-layered-nav').each(function(){
		originalHeightLeft += $(this).height();
	});
	
	var runningHeight = originalHeightLeft - leftNavRemoveHeight;

//	var originalHeightRight = 0;
//	$('div.col-right div').each(function(){
//		originalHeightRight += $(this).height();
//	});
	
	
	
	function goColumnEqualizer(showOneFilter) {
		
		/*if(showOneFilter){
			var leftColHeight = runningHeight;
			isSingleFilter = false;
		}else{
			var leftColHeight = originalHeightLeft - leftNavRemoveHeight;
		}*/
		
		switch(showOneFilter) {
		
			case 0:
				var leftColHeight = originalHeightLeft - leftNavRemoveHeight;
				leftColHeight -= 120;
				break;
			case 1:
				var leftColHeight = runningHeight;
				isSingleFilter = 0;
				break;
			case 2:
				var leftColHeight = originalHeightLeft - leftNavRemoveHeight;
				break;
			default:
				break;
		}
		
		
		var originalHeightContent = $('div.col-main div.category-view').height() + $('div.col-main #catProdCompare').height() + 30;
		
		var mainColHeight = originalHeightContent;
		
		

	
		if (leftColHeight > mainColHeight) {
			finalColHeight = leftColHeight;
		} else {
			finalColHeight = mainColHeight;
		}
		
		$('div.col-left').height(finalColHeight+31);
		$('div.col-main').height(finalColHeight);
		

	}
	
	function addHeightGoColumnEqualizer(showOneFilter) {
		/*alert('leftColHeight before addition = ' + leftColHeight);*/
		/*alert('originalHeightLeft = ' + originalHeightLeft);*/
		/*if(showOneFilter){
			
			var leftColHeight = runningHeight;
			isSingleFilter = false;
		}else{
			var leftColHeight = originalHeightLeft;
		}*/
		
		switch(showOneFilter) {
			
			case 1:
				var leftColHeight = runningHeight;
				isSingleFilter = 0;
				break;
			case 2:
				var leftColHeight = originalHeightLeft;
				break;
			default:
				break;				
		}
		
		
		
		var originalHeightContent = $('div.col-main div.category-view').height() + $('div.col-main #catProdCompare').height() + 30;
		var mainColHeight = originalHeightContent;
		
		/*alert('leftColHeight = ' + leftColHeight);
		alert('mainColHeight = ' + mainColHeight);*/
	
		if (leftColHeight > mainColHeight) {
			finalColHeight = leftColHeight;
		} else {
			finalColHeight = mainColHeight;
		}
		
		$('div.col-left').height(finalColHeight+20);
		$('div.col-main').height(finalColHeight);
			

	}
	
	// initialize the page columns
	if ( $('body.catalog-category-view div.col-main div.category-view').length ) {
		goColumnEqualizer(isSingleFilter);
	}
	
	
  


//} categoryColumnEqualizer();
// ----------------------------------------------------------------------------------------
// END Column equalizer
// ----------------------------------------------------------------------------------------

//---------------------------------------------------------------------------
//	START category preview image
//---------------------------------------------------------------------------
	$('div.category-products ul.products-grid li.item').each(function() {
		tempMPN = $('div.productModel span', $(this)).html();
		$(this).append('<img id="previewImageTrigger'+tempMPN+'" class="previewImageTrigger" src="/skin/frontend/discountid/did_theme_three/images/category/product_zoom_icon.gif" width="24" height="24" border="0" />');
		$('.previewImageTrigger', $(this)).mouseenter(function(){
			var triggerOffset = $(this).offset();
			$('div.category-products').append('<div id="productPreviewImage" style="display:none;"><img id="productPreviewImageActual" src="'+ $('span.previewImageURL', $(this).parent()).html() +'" width="370" height="370" /></div>');
			if ( $(this).closest('li').hasClass('last') ) {
				$('#productPreviewImage').css({'top':triggerOffset.top+25+'px','left':(triggerOffset.left-160)+'px'}).show();
			} else {
				$('#productPreviewImage').css({'top':triggerOffset.top+25+'px','left':triggerOffset.left+'px'}).show();
			}
		}).mouseleave(function(){
			$('#productPreviewImage').remove();
//			$('div.category-products ul.products-grid li.item').css({'z-index':'1'});
		});
	});
//---------------------------------------------------------------------------
//	END category preview image
//---------------------------------------------------------------------------

});




jQuery(document).ready(function($){

//---------------------------------------------------------------------------
//	START category header positioning
//---------------------------------------------------------------------------
	$(window).load(function(){
		// vertical align copy first																														 
		var categoryHeaderHeight =  $('#categoryHeader').height();
		var categoryHeaderCopyHeight = $('#categoryHeaderCopy').height();
		var categoryHeaderCopyHeightMargin = (categoryHeaderHeight - categoryHeaderCopyHeight) / 2;
		$('#categoryHeaderCopy').css({'padding-top':categoryHeaderCopyHeightMargin+'px','padding-bottom':categoryHeaderCopyHeightMargin+'px'});
		// vertical align image last
		var categoryHeaderHeight =  $('#categoryHeader').height();
		var categoryHeaderImageHeight = $('#categoryHeaderImage').height();
		var categoryHeaderImageImageHeight = $('#categoryHeaderImage img.category-image').height();
		var categoryHeaderImageHeightMargin = (categoryHeaderHeight - categoryHeaderImageImageHeight) / 2;
		$('#categoryHeaderImage img.category-image').css({'padding-top':categoryHeaderImageHeightMargin,'padding-bottom':categoryHeaderImageHeightMargin});
	});
		
//---------------------------------------------------------------------------
//	END category header positioning
//---------------------------------------------------------------------------

	

});



//---------------------------------------------------------------------------
//	START yousave (category)
//---------------------------------------------------------------------------

	function categorySavings(categorySavingsVersion) {
		jQuery(document).ready(function($){
			var savingsCounter = 0;
			$('div.category-products ul.products-grid li.item').each(function() {
				tempRetailPrice = $('div.price-box p.old-price span.price span.price', $(this)).html();
				tempStorePrice = $('div.price-box p.special-price span.price span.price', $(this)).html();
				if ( $('div.price-box p.special-price span.price span.loginForPrice', $(this)).length > 0 ) {
					tempStorePrice = "Login for Price";
				} else {
					if (tempStorePrice == null || tempStorePrice == "") {
						tempRetailPrice = $('div.price-box p.old-price span.price', $(this)).html();
						tempStorePrice = $('div.price-box p.special-price span.price', $(this)).html();
					}
					if (tempRetailPrice == null || tempRetailPrice == "") {tempRetailPrice = "0.00"}
					if (tempStorePrice == null || tempStorePrice == "") {tempStorePrice = "0.00"}
					if (tempStorePrice.indexOf("Login for Price") == -1) {
						// convert values from currency to numbers
						tempRetailPrice = tempRetailPrice.replace(' ','');
						tempRetailPrice = tempRetailPrice.replace('$','');
						tempRetailPrice = tempRetailPrice.replace(',','');
						tempStorePrice = tempStorePrice.replace(' ','');
						tempStorePrice = tempStorePrice.replace('$','');
						tempStorePrice = tempStorePrice.replace(',','');
						tempSavedPrice = (Math.round( (tempRetailPrice - tempStorePrice) *100) /100).toString();
					}
						
					
	// START decimal fix ------------------------------------------------------------					
						// is there a decimal place?
						if (tempSavedPrice.indexOf("\.") > -1) {
							// split on the decimal
							mySplitResult = tempSavedPrice.split("\.");
							if (mySplitResult.length > 1) {
								if (mySplitResult[1].length < 2) {
									tempSavedPrice = tempSavedPrice + "0";
								}
							}
						} else {
							// no decimal, so add .00
							tempSavedPrice = tempSavedPrice + ".00";
						}
	// END decimal fix ------------------------------------------------------------
	
	// START comma fix ------------------------------------------------------------
							// split on the decimal
						mySplitResult = tempSavedPrice.split("\.");
						if (mySplitResult.length > 1) {
							// are there more than 3 characters to the left of the period?
							if (mySplitResult[0].length > 3) {
								commasToAdd = parseInt(mySplitResult[0].length / 3);
								if (commasToAdd > 0) {
									x1 = mySplitResult[0];
									var rgx = /(\d+)(\d{3})/;
									while (rgx.test(x1)) {
										x1 = x1.replace(rgx, '$1' + ',' + '$2');
									}
								}
								tempSavedPrice = x1 + "." + mySplitResult[1];
							}
						}
	// END comma fix ------------------------------------------------------------
	
	
	
						tempPercentSaved = Math.round(100 - ((tempStorePrice / tempRetailPrice) * 100));
						
						$('#youSavePercent, #youSaveDollar, #youSaveDollarPercent', $(this)).hide();
						switch (categorySavingsVersion) {
							case 0:
								break;
							case 1:
								$('#youSavePercent span.yousave-percent', $(this)).html(tempPercentSaved);
								$('#youSavePercent', $(this)).show();
								$('div.price-box p.old-price span.price', $(this)).css({'text-decoration':'line-through'});
								break;
							case 2:
								$('#youSaveDollar span.yousave-dollar', $(this)).html(tempSavedPrice);
								$('#youSaveDollar', $(this)).show();
								$('div.price-box p.old-price span.price', $(this)).css({'text-decoration':'line-through'});
								break;
							case 3:
								if(tempPercentSaved > 0){
									$('#youSaveDollarPercent span.yousave-dollar', $(this)).html(tempSavedPrice);
									$('#youSaveDollarPercent span.yousave-percent', $(this)).html(tempPercentSaved);
									$('#youSaveDollarPercent', $(this)).show();
									$('div.price-box p.old-price span.price', $(this)).css({'text-decoration':'line-through'});
								} else {
									$('div.price-box p.old-price', $(this)).hide();
								}
								break;
							default:
								break;
						}
				}
				
				savingsCounter++;
			});
			
//			compareHeight = $('#catProdCompare').height();
//			if (compareHeight == null || compareHeight == "") { compareHeight = 0; }
//			savingsCounter = (savingsCounter / 4) + compareHeight - 100;
//			tempCatLeftHeight = $('div.col-left').height();
//			tempCatContentHeight = $('div.col-main').height();
//			if (tempCatLeftHeight > tempCatContentHeight) {
//				$('div.col-main').height(tempCatLeftHeight + savingsCounter);
//			} else {
//				$('div.col-left').height(tempCatContentHeight);
//			}

			
			if ( $('body.catalog-category-view div.col-main div.category-view').length ) {
				contentPaddingBottom = 20;
				contentExtaPadding = 80;
				tempCatLeftHeight = contentPaddingBottom + $('div.col-left').height();
				tempCatProductCompareHeight = $('#catProdCompare').height();
				if (tempCatProductCompareHeight == null || tempCatProductCompareHeight == "") {tempCatProductCompareHeight = 0;}
				tempCatProductContentHeight = $('div.col-main div.category-view').height();
				$('div.col-main').height(tempCatProductCompareHeight+tempCatProductContentHeight+contentPaddingBottom+contentExtaPadding);
				$('div.col-left').height( $('div.col-left').height() + (contentPaddingBottom*2) + contentExtaPadding );
				
				if (tempCatLeftHeight > (tempCatProductCompareHeight+tempCatProductContentHeight+contentPaddingBottom)) {
					$('div.col-main').height(tempCatLeftHeight);
				} else {
					$('div.col-left').height(tempCatProductCompareHeight+tempCatProductContentHeight+(contentPaddingBottom*2)+contentExtaPadding);
				}
			}
			
			
		});
	}
	
		
//---------------------------------------------------------------------------
//	END yousave  (category)
//---------------------------------------------------------------------------



//---------------------------------------------------------------------------
//	START yousave (product page)
//---------------------------------------------------------------------------

	function productSavings(categorySavingsVersion) {
		jQuery(document).ready(function($){
			$('body.catalog-product-view div.product-view div.product-shop').each(function() {
				tempRetailPrice = $('div.price-box p.old-price span.price span.price', $(this)).html();
				tempStorePrice = $('div.price-box p.special-price span.price span.price', $(this)).html();
				if ( $('div.price-box p.special-price span.price span.loginForPrice', $(this)).length > 0 ) {
					tempStorePrice = "Login for Price";
				} else {
					if (tempStorePrice == null || tempStorePrice == "") {
						tempRetailPrice = $('div.price-box p.old-price span.price', $(this)).html();
						tempStorePrice = $('div.price-box p.special-price span.price', $(this)).html();
					}
					if (tempRetailPrice == null || tempRetailPrice == "") {tempRetailPrice = "0.00"}
					if (tempStorePrice == null || tempStorePrice == "") {tempStorePrice = "0.00"}
					if (tempStorePrice.indexOf("Login for Price") == -1) {
						// convert values from currency to numbers
						tempRetailPrice = tempRetailPrice.replace(' ','');
						tempRetailPrice = tempRetailPrice.replace('$','');
						tempRetailPrice = tempRetailPrice.replace(',','');
						tempStorePrice = tempStorePrice.replace(' ','');
						tempStorePrice = tempStorePrice.replace('$','');
						tempStorePrice = tempStorePrice.replace(',','');
						tempSavedPrice = (Math.round( (tempRetailPrice - tempStorePrice) *100) /100).toString();
					}
						
					
	// START decimal fix ------------------------------------------------------------					
						// is there a decimal place?
						if (tempSavedPrice.indexOf("\.") > -1) {
							// split on the decimal
							mySplitResult = tempSavedPrice.split("\.");
							if (mySplitResult.length > 1) {
								if (mySplitResult[1].length < 2) {
									tempSavedPrice = tempSavedPrice + "0";
								}
							}
						} else {
							// no decimal, so add .00
							tempSavedPrice = tempSavedPrice + ".00";
						}
	// END decimal fix ------------------------------------------------------------
	
	// START comma fix ------------------------------------------------------------
							// split on the decimal
						mySplitResult = tempSavedPrice.split("\.");
						if (mySplitResult.length > 1) {
							// are there more than 3 characters to the left of the period?
							if (mySplitResult[0].length > 3) {
								commasToAdd = parseInt(mySplitResult[0].length / 3);
								if (commasToAdd > 0) {
									x1 = mySplitResult[0];
									var rgx = /(\d+)(\d{3})/;
									while (rgx.test(x1)) {
										x1 = x1.replace(rgx, '$1' + ',' + '$2');
									}
								}
								tempSavedPrice = x1 + "." + mySplitResult[1];
							}
						}
	// END comma fix ------------------------------------------------------------
	
	
	
						tempPercentSaved = Math.round(100 - ((tempStorePrice / tempRetailPrice) * 100));
						$('#youSavePercent, #youSaveDollar, #youSaveDollarPercent', $(this)).hide();
						switch (categorySavingsVersion) {
							case 0:
								break;
							case 1:
								$('#youSavePercent span.yousave-percent', $(this)).html(tempPercentSaved);
								$('#youSavePercent', $(this)).show();
								$('div.price-box p.old-price span.price', $(this)).css({'text-decoration':'line-through'});
								break;
							case 2:
								$('#youSaveDollar span.yousave-dollar', $(this)).html(tempSavedPrice);
								$('#youSaveDollar', $(this)).show();
								$('div.price-box p.old-price span.price', $(this)).css({'text-decoration':'line-through'});
								break;
							case 3:
								if(tempPercentSaved > 0){
									$('#youSaveDollarPercent span.yousave-dollar', $(this)).html(tempSavedPrice);
									$('#youSaveDollarPercent span.yousave-percent', $(this)).html(tempPercentSaved);
									$('#youSaveDollarPercent', $(this)).show();
									$('div.price-box p.old-price span.price', $(this)).css({'text-decoration':'line-through'});
								} else {
									$('div.price-box p.old-price', $(this)).hide();
								}
								break;
							default:
								break;
						}
				}
			});
		});
	}


//-------------------------------------------------------------------------------------------------------------------------------------------------------------

	function productSavingsOLD(productSavingsVersion) {
		jQuery(document).ready(function($){
			$('body.catalog-product-view div.product-view div.product-shop').each(function() {
				tempRetailPrice = $('div.price-box p.old-price span.price ', $(this)).html();
				tempStorePrice = $('div.price-box p.special-price span.price', $(this)).html();
				
				if (tempRetailPrice == null || tempRetailPrice == "") {tempRetailPrice = "0.00"}
				if (tempStorePrice == null || tempStorePrice == "") {tempStorePrice = "0.00"}
				
				if (tempStorePrice.indexOf("Login for Price") == -1) {
					// convert values from currency to numbers
					tempRetailPrice = tempRetailPrice.replace(' ','');
					tempRetailPrice = tempRetailPrice.replace('$','');
					tempRetailPrice = tempRetailPrice.replace(',','');
					tempStorePrice = tempStorePrice.replace(' ','');
					tempStorePrice = tempStorePrice.replace('$','');
					tempStorePrice = tempStorePrice.replace(',','');
					tempSavedPrice = (Math.round( (tempRetailPrice - tempStorePrice) *100) /100).toString();
					
// START decimal fix ------------------------------------------------------------					
					// is there a decimal place?
					if (tempSavedPrice.indexOf("\.") > -1) {
						// split on the decimal
						mySplitResult = tempSavedPrice.split("\.");
						if (mySplitResult.length > 1) {
							if (mySplitResult[1].length < 2) {
								tempSavedPrice = tempSavedPrice + "0";
							}
						}
					} else {
						// no decimal, so add .00
						tempSavedPrice = tempSavedPrice + ".00";
					}
// END decimal fix ------------------------------------------------------------

// START comma fix ------------------------------------------------------------
						// split on the decimal
					mySplitResult = tempSavedPrice.split("\.");
					if (mySplitResult.length > 1) {
						// are there more than 3 characters to the left of the period?
						if (mySplitResult[0].length > 3) {
							commasToAdd = parseInt(mySplitResult[0].length / 3);
							if (commasToAdd > 0) {
								x1 = mySplitResult[0];
								var rgx = /(\d+)(\d{3})/;
								while (rgx.test(x1)) {
									x1 = x1.replace(rgx, '$1' + ',' + '$2');
								}
							}
							tempSavedPrice = x1 + "." + mySplitResult[1];
						}
					}
// END comma fix ------------------------------------------------------------
					
					tempPercentSaved = Math.round(100 - ((tempStorePrice / tempRetailPrice) * 100));
					
					$('#youSavePercent, #youSaveDollar, #youSaveDollarPercent', $(this)).hide();
					
					switch (productSavingsVersion) {
						case 0:
							break;
						case 1:
							$('#youSavePercent span.yousave-percent', $(this)).html(tempPercentSaved);
							$('#youSavePercent', $(this)).show();
							$('div.price-box p.old-price span.price', $(this)).css({'text-decoration':'line-through'});
							break;
						case 2:
							$('#youSaveDollar span.yousave-dollar', $(this)).html(tempSavedPrice);
							$('#youSaveDollar', $(this)).show();
							$('div.price-box p.old-price span.price', $(this)).css({'text-decoration':'line-through'});
							break;
						case 3:
							$('#youSaveDollarPercent span.yousave-dollar', $(this)).html(tempSavedPrice);
							$('#youSaveDollarPercent span.yousave-percent', $(this)).html(tempPercentSaved);
							$('#youSaveDollarPercent', $(this)).show();
							$('div.price-box p.old-price span.price', $(this)).css({'text-decoration':'line-through'});
							break;
						default:
							break;
					}
				}
			});
		});
	}
	
//	categorySavings(3);	productSavings(3);
	
//---------------------------------------------------------------------------
//	END yousave (product page)
//---------------------------------------------------------------------------


	






//---------------------------------------------------------------------------
//	START product tabs failsafe
//---------------------------------------------------------------------------

jQuery(document).ready(function($){
	var isTabsLoaded = false;
	function reInitTabs() {
		// Is this a catalog product view page
		if ( $('body.catalog-product-view').length && isTabsLoaded == false ) {
			// If the Tabs script has not initialized
			if ($('#container-1 ul.ui-tabs-nav').length < 1)	{
				var $tabs = $('#container-1 > ul').tabs();
				$('div.prSnippetReadReviews a.prSnippetLink').live('click', function(){
					$tabs.tabs('select', 2); // switch to third tab, 0 based array.
					tempDivTabsContainer = $('div.product-collateral').offset();
					scrollTo(0,tempDivTabsContainer.top-20);
					return false;
				});
				setTimeout(reInitTabs, 250);
			} else {
				isTabsLoaded = true;
			}
		}
	}
	reInitTabs();
});

//---------------------------------------------------------------------------
//	END product tabs failsafe
//---------------------------------------------------------------------------





//-----------------------------------------------------------------------------------------------------------
// START track youtube clicks.
//-----------------------------------------------------------------------------------------------------------
jQuery(document).ready(function($){
	$('a[href^="http://www.youtube.com/"]').click(function(){
		_gaq.push(["_setAccount", "UA-325904-1"]);
    _gaq.push(["_trackPageview", '/youtube/'+ $(this).attr('href')]);
	});
});
//-----------------------------------------------------------------------------------------------------------
// END track youtube clicks.
//-----------------------------------------------------------------------------------------------------------


//-----------------------------------------------------------------------------------------------------------
// START track header live chat clicks.
//-----------------------------------------------------------------------------------------------------------
jQuery(document).ready(function($){
	$('#headerSubNav #liveChatBox a img').click(function(){
		_gaq.push(["_setAccount", "UA-325904-1"]);
    _gaq.push(["_trackPageview", "/livechat/header-link-click"]);
	});
});
//-----------------------------------------------------------------------------------------------------------
// END track header live chat clicks.
//-----------------------------------------------------------------------------------------------------------




//-----------------------------------------------------------------------------------------------------------
// START checkout tweaks
//-----------------------------------------------------------------------------------------------------------

jQuery(document).ready(function($){
	
	// Adds a # to the left of each checkout progress step for the side nav.
	var checkoutProgressStep = 0;
	$('div.opc-block-progress div.block-content dt').each( function() {
		checkoutProgressStep++;
		$(this).prepend(checkoutProgressStep+'.&nbsp;');
	});
	
//	$('#billing:street2').closest('li').prepend("<label for='billing:street2'>&nbsp;</label>");	
	
});

//-----------------------------------------------------------------------------------------------------------
// End checkout tweaks
//-----------------------------------------------------------------------------------------------------------





// ----------------------------------------------------------------------------------------
// START Ceebox
// ----------------------------------------------------------------------------------------


/*
 * Ceebox 1.0
 * By Colin Fahrion (http://www.catcubed.com)
 * Adapted from Thickbox (http://jquery.com/demo/thickbox/) Copyright (c) 2007 Cody Lindley (http://www.codylindley.com)
 * Video pop-up code inspired by Videobox (http://videobox-lb.sourceforge.net/)
 * Copyright (c) 2008 Colin Fahrion
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
*/

// Change base settings below	  
var cee_pathToImage = "/Images/loadinganimation.gif";
var cee_htmlBaseWidth = 1000
var cee_htmlBaseHeight = 400
var cee_videoBaseWidth = 500
var cee_videoBaseHeight = 360


/*!!!!!!!!!!!!!!!!! edit below this line at your own risk !!!!!!!!!!!!!!!!!!!!!!!*/

//on page load call cee_init
jQuery(document).ready(function($){   
																
//jQuery(document).ready(function($){
	cee_init('a.ceebox, area.ceebox, input.ceebox');//pass where to apply ceebox
	imgLoader = new Image();// preload image
	imgLoader.src = cee_pathToImage;
//});

//add ceebox to href & area elements that have a class of .ceebox
function cee_init(domChunk){
	$(domChunk).click(function(){
		if ( (!$.browser.msie) || ( $.browser.msie && (parseFloat($.browser.version)) > 6 )) {
			var t = this.title || this.name || null;
			var a = this.href || this.alt;
			var g = this.rel || false;
			cee_show(t,a,g);
			this.blur();
			return false;
		}
	});
}

function cee_show(caption, url, rel) {//function called when the user clicks on a ceebox link

	try {
		if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
			$("body","html").css({height: "100%", width: "100%"});
			$("html").css("overflow","hidden");
			if (document.getElementById("cee_HideSelect") === null) {//iframe to hide select elements in ie6
				$("body").append("<iframe id='cee_HideSelect'></iframe><div id='cee_overlay'></div><div id='cee_window'></div>");
				$("#cee_overlay").click(cee_remove);
			}
		}else{//all others
			if(document.getElementById("cee_overlay") === null){
				$("body").append("<div id='cee_overlay'></div><div id='cee_window'></div>");
				$("#cee_overlay").click(cee_remove);
			}
		}
		
		if(cee_detectMacXFF()){
			$("#cee_overlay").addClass("cee_overlayMacFFBGHack");//use png overlay so hide flash
		}else{
			$("#cee_overlay").addClass("cee_overlayBG");//use background and opacity
		}
		
		if(caption===null){caption="";}
		$("body").append("<div id='cee_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
		$('#cee_load').show();//show loader
		
		var baseURL;
		if(url.indexOf("?")!==-1){ //ff there is a query string involved
			baseURL = url.substr(0, url.indexOf("?"));
		}else{ 
	   		baseURL = url;
		}
		
		var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$|\.swf$|\.htm$|\.html$|\.asp$|\.aspx$/;
		var urlType = baseURL.toLowerCase().match(urlString);
		
		if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp'){
			//Display images in box
			cee_PrevCaption = "";
			cee_PrevURL = "";
			cee_PrevHTML = "";
			cee_NextCaption = "";
			cee_NextURL = "";
			cee_NextHTML = "";
			cee_imageCount = "";
			cee_FoundURL = false;
			if(rel){
				cee_TempArray = $("a[@rel="+rel+"]").get();
				for (cee_Counter = 0; ((cee_Counter < cee_TempArray.length) && (cee_NextHTML === "")); cee_Counter++) {
					var urlTypeTemp = cee_TempArray[cee_Counter].href.toLowerCase().match(urlString);
						if (!(cee_TempArray[cee_Counter].href == url)) {						
							if (cee_FoundURL) {
								cee_NextCaption = cee_TempArray[cee_Counter].title;
								cee_NextURL = cee_TempArray[cee_Counter].href;
								cee_NextHTML = "<span id='cee_next'>&nbsp;&nbsp;<a href='#'>Next &gt;</a></span>";
							} else {
								cee_PrevCaption = cee_TempArray[cee_Counter].title;
								cee_PrevURL = cee_TempArray[cee_Counter].href;
								cee_PrevHTML = "<span id='cee_prev'>&nbsp;&nbsp;<a href='#'>&lt; Prev</a></span>";
							}
						} else {
							cee_FoundURL = true;
							cee_imageCount = "Image " + (cee_Counter + 1) +" of "+ (cee_TempArray.length);											
						}
				}
			}

			imgPreloader = new Image();
			imgPreloader.onload = function(){		
			imgPreloader.onload = null;
				
			// Resizing large images - orginal by Christian Montoya edited by Cody Lindley.
			var pagesize = cee_getPageSize();
			var x = pagesize[0] - 150;
			var y = pagesize[1] - 150;
			var imageWidth = imgPreloader.width;
			var imageHeight = imgPreloader.height;
			if (imageWidth > x) {
				imageHeight = imageHeight * (x / imageWidth); 
				imageWidth = x; 
				if (imageHeight > y) { 
					imageWidth = imageWidth * (y / imageHeight); 
					imageHeight = y; 
				}
			} else if (imageHeight > y) { 
				imageWidth = imageWidth * (y / imageHeight); 
				imageHeight = y; 
				if (imageWidth > x) { 
					imageHeight = imageHeight * (x / imageWidth); 
					imageWidth = x;
				}
			}
			// End Resizing
			
			$("#cee_window").append("<a href='' id='cee_ImageOff' title='Close'><img id='cee_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+caption+"'/></a>" + "<div id='cee_caption'>"+caption+"<div id='cee_secondLine'>" + cee_imageCount + cee_PrevHTML + cee_NextHTML + "</div></div><div id='cee_closeWindow'><a href='#' id='cee_closeWindowButton' title='Close'>close</a> or Esc Key</div>"); 		
			
			$("#cee_closeWindowButton").click(cee_remove);
			
			if (!(cee_PrevHTML === "")) {
				function goPrev(){
					if($(document).unbind("click",goPrev)){$(document).unbind("click",goPrev);}
					$("#cee_window").remove();
					$("body").append("<div id='cee_window'></div>");
					cee_show(cee_PrevCaption, cee_PrevURL, rel);
					return false;	
				}
				$("#cee_prev").click(goPrev);
			}
			
			if (!(cee_NextHTML === "")) {		
				function goNext(){
					$("#cee_window").remove();
					$("body").append("<div id='cee_window'></div>");
					cee_show(cee_NextCaption, cee_NextURL, rel);				
					return false;	
				}
				$("#cee_next").click(goNext);
				
			}

			document.onkeydown = function(e){ 	
				if (e == null) { // ie
					keycode = event.keyCode;
				} else { // mozilla
					keycode = e.which;
				}
				if(keycode == 27){ // close
					cee_remove();
				} else if(keycode == 190){ // display previous image
					if(!(cee_NextHTML == "")){
						document.onkeydown = "";
						goNext();
					}
				} else if(keycode == 188){ // display next image
					if(!(cee_PrevHTML == "")){
						document.onkeydown = "";
						goPrev();
					}
				}	
			};
			
			cee_position(imageWidth + 30,imageHeight + 60);
			$("#cee_load").remove();
			$("#cee_ImageOff").click(cee_remove);
			$("#cee_window").css({display:"block"}); //for safari using css instead of show
			};
			
			imgPreloader.src = url;
		}else if (urlType == '.swf' && !url.match(/metacafe\.com\/watch/i)){
			//code to show swf. Added by Colin Fahrion.
			var vidSize = cee_getSize(rel);
			//create cee_window
			$("#cee_window").append("<div id='cee_video'>Video not available</div>" + "<div id='cee_caption'>"+caption+"</div><div id='cee_closeWindow'><a href='#' id='cee_closeWindowButton' title='Close'>close</a> or Esc Key</div>"); 		
			$("#cee_closeWindowButton").click(cee_remove);
			cee_position(vidSize[0] + 30,vidSize[1] + 60);
			
			//embed swfobject
			swfobject.embedSWF(url, "cee_video", vidSize[0], vidSize[1], "9.0.0", false, {autoPlay:"true"}, {wmode:"transparent"}, {});
			$("#cee_load").remove();
			$("#cee_window").css({display:"block"}); //for safari using css instead of show
		}else if (url.match(/youtube\.com\/watch/i)){
			var vidSize = cee_getSize(rel);
			var vidId = url.split('v=')[1].split('&')[0];
			var vidSrc = "http://www.youtube.com/v/"+vidId+"&hl=en&fs=1&autoplay=1"
			var flashvars = {};
			var params = {};
			params.wmode = "transparent";
			params.allowFullScreen = "true";
			params.allowscriptaccess = "always";
			var attributes = {};
			
			cee_vidWindow(vidSize,caption);

			//embed swfobject
			swfobject.embedSWF(vidSrc, "cee_video", vidSize[0], vidSize[1], "9.0.0", false, flashvars, params, attributes);
			$("#cee_load").remove();
			$("#cee_window").css({display:"block"}); //for safari using css instead of show
			
		}else if (url.match(/google\.com\/videoplay/i)) {
			//play google video in swf player
			var vidSize = cee_getSize(rel);
			var vidId = url.split('id=')[1].split('&')[0];
			var vidSrc = "http://video.google.com/googleplayer.swf?docId="+vidId+"&hl=en"
			var flashvars = {};
			flashvars.autoPlay = "true";
			flashvars.playerMode = "normal";
			flashvars.fs = "true";
			var params = {};
			params.wmode = "transparent";
			params.allowFullScreen = "true";
			params.allowscriptaccess = "always";
			var attributes = {};
			attributes.allowfullscreen = "true";
			attributes.allowscriptaccess = "always";
			
			cee_vidWindow(vidSize,caption);
			//embed swfobject
			swfobject.embedSWF(vidSrc, "cee_video", vidSize[0], vidSize[1], "9.0.0", false, flashvars, params, attributes);
			$("#cee_load").remove();
			$("#cee_window").css({display:"block"}); //for safari using css instead of show
		}else if(url.match(/metacafe\.com\/watch/i)){
			//play metacafe video in swf player
			var vidSize = cee_getSize(rel);
			var vidId = url.split('id=')[1].split('&')[0];
			var vidSrc = "http://www.metacafe.com/fplayer/"+vidID+"/.swf"
			var flashvars = {};
			var params = {};
			params.wmode = "transparent";
			var attributes = {};
			
			cee_vidWindow(vidSize,caption);
			
			//embed swfobject
			swfobject.embedSWF(vidSrc, "cee_video", vidSize[0], vidSize[1], "9.0.0", false, flashvars, params, attributes);
			$("#cee_load").remove();
			$("#cee_window").css({display:"block"}); //for safari using css instead of show
		}else if(url.match(/ifilm\.com\/video/i)){
			//play ifilm video in swf player
			var vidSize = cee_getSize(rel);
			var vidId = url.split('id=')[1].split('&')[0];
			var vidSrc = "http://www.ifilm.com/efp"
			var flashvars = {};
			flashvars.flvbaseclip = videoId+"&";
			var params = {};
			params.wmode = "transparent";
			var attributes = {};
			
			cee_vidWindow(vidSize,caption);
			
			//embed swfobject
			swfobject.embedSWF(vidSrc, "cee_video", vidSize[0], vidSize[1], "9.0.0", false, flashvars, params, attributes);
			$("#cee_load").remove();
			$("#cee_window").css({display:"block"}); //for safari using css instead of show
		}else if ((!url.match(/^http:+/) && (rel && !rel.match("iframe"))) || (rel && rel.match("ajax"))){
			//if indicated as ajax display as such; also, show relative path links as ajax unless indicated as iframe
			var windowSize = cee_getSize(rel,700,400);
			ajaxContentW = windowSize[0]
			ajaxContentH = windowSize[1] - 5;
			
			if($("#cee_window").css("display") != "block"){ //if window currently not displaying
				if(rel && rel.match("modal")){//modal ajax ceebox
					$("#cee_overlay").unbind();
					$("#cee_window").append("<div id='cee_ajaxContent' class='cee_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");	
					document.onkeyup = function(e){ 	
						if (e == null) { // ie
							keycode = event.keyCode;
						} else { // mozilla
							keycode = e.which;
						}
						if(keycode == 27){ // close
							cee_remove();
						}
					};
				}else{//normal non-modal ajax
					$("#cee_window").append("<div id='cee_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px'></div><div id='cee_title'><div id='cee_ajaxWindowTitle'>"+caption+"</div><div id='cee_closeAjaxWindow'><a href='#' id='cee_closeWindowButton'>close</a> or Esc Key</div></div>");
				}
			}else{ //if the window is already up, we are just loading new content via ajax
				$("#cee_ajaxContent")[0].style.width = ajaxContentW +"px";
				$("#cee_ajaxContent")[0].style.height = ajaxContentH +"px";
				$("#cee_ajaxContent")[0].scrollTop = 0;
				$("#cee_ajaxWindowTitle").html(caption);
			}
			$("#cee_closeWindowButton").click(cee_remove);
			if (rel && rel.match(/#[a-z_A-Z1-9]+/)){ //if the user as supplied a id to target in the rel than use that
				targetId = rel.match(/#[a-z_A-Z1-9]+/);
				$("#cee_ajaxContent").load(url + " " + targetId);
			} else {
				$("#cee_ajaxContent").load(url);
			}
			
			cee_position(windowSize[0]+30, windowSize[0]+40);
			$("#cee_load").remove();
			cee_init("#cee_ajaxContent a.ceebox");
			$("#cee_window").css({display:"block"});
			
		}else{
			//else show as iframe (catch-all)
			var windowSize = cee_getSize(rel,700,400);
			ajaxContentW = windowSize[0]
			ajaxContentH = windowSize[1] - 5;
			
			$("#cee_iframeContent").remove();
			if (rel && rel.match("modal")) {//modal iframe ceebox
				$("#cee_overlay").unbind();
				$("#cee_window").append("<iframe frameborder='0' hspace='0' src='"+url+"' id='cee_iframeContent' name='cee_iframeContent"+Math.round(Math.random()*1000)+"' onload='cee_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;'> </iframe>");
				document.onkeyup = function(e){ 	
					if (e == null) { // ie
						keycode = event.keyCode;
					} else { // mozilla
						keycode = e.which;
					}
					if(keycode == 27){ // close
						cee_remove();
					}	
				};
			} else {//normal non-modal iframe ceebox (this is what it defaults to)
				$("#cee_window").append("<iframe frameborder='0' hspace='0' src='"+url+"' id='cee_iframeContent' name='cee_iframeContent"+Math.round(Math.random()*1000)+"' onload='cee_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;' > </iframe><div id='cee_title'><div id='cee_ajaxWindowTitle'>"+caption+"</div><div id='cee_closeAjaxWindow'><a href='#' id='cee_closeWindowButton' title='Close'>close</a> or Esc Key</div></div>");
			}
			$("#cee_closeWindowButton").click(cee_remove);
			cee_position(windowSize[0]+30, windowSize[0]+40);
			if($.browser.safari){//safari needs help because it will not fire iframe onload
				$("#cee_load").remove();
				$("#cee_window").css({display:"block"});
			}
		}
		
	} catch(e) {
		//nothing here
	}
}

//helper functions below
function cee_showIframe(){
	$("#cee_load").remove();
	$("#cee_window").css({display:"block"});
}

function cee_remove() {
 	$("#cee_imageOff").unbind("click");
	$("#cee_closeWindowButton").unbind("click");
	$("#cee_window").fadeOut("fast",function(){$('#cee_window,#cee_overlay,#cee_HideSelect').trigger("unload").unbind().remove();});
	$("#cee_load").remove();
	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
		$("body","html").css({height: "auto", width: "auto"});
		$("html").css("overflow","");
	}
	document.onkeydown = "";
	document.onkeyup = "";
	return false;
}

function cee_position(w,h) {
$("#cee_window").css({marginLeft: '-' + parseInt((w / 2),10) + 'px', width: w + 'px'});
	if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
		$("#cee_window").css({marginTop: '-' + parseInt((h / 2),10) + 'px'});
	}
}

function cee_getSize(rel,baseW,baseH){	
			//To set width and height for the video use the rel attribute. I.E., rel="600 480"
			(baseW)? baseW=baseW*1 : baseW=cee_videoBaseWidth;
			(baseH)? baseH=baseH*1 : baseH=cee_videoBaseHeight;
			var sizes=new Array();
			if (rel && rel.match(/[0-9]+/g)){
				sizes = rel.match(/[0-9]+/g);
				(sizes[0])? sizes[0] = sizes[0]*1 : sizes[0] = baseW;
				(sizes[1])? sizes[1] = sizes[1]*1 : sizes[0] = baseH;
			} else {
				sizes = [baseW,baseH];
			}
			return sizes;
}

function cee_vidWindow(vidSize,caption) {
	//create ceebox window for video
	$("#cee_window").append("<div id='cee_video'>Video not available</div>" + "<div id='cee_caption'>"+caption+"</div><div id='cee_closeWindow'><a href='#' id='cee_closeWindowButton' title='Close'>close</a> or Esc Key</div>"); 		
	$("#cee_closeWindowButton").click(cee_remove);
	cee_position(vidSize[0] + 30,vidSize[1] + 60);
}

function cee_getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	arrayPageSize = [w,h];
	return arrayPageSize;
}

function cee_detectMacXFF() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
    return true;
  }
}


});


// ----------------------------------------------------------------------------------------
// END Ceebox
// ----------------------------------------------------------------------------------------












