                                                                                                        // CHARACTER COUNT AND CUT 

try{
var headerNum = 85;
var paraNum = 150;

// CHECKS FOR IE
var browserName=navigator.appName;
 if (browserName=="Microsoft Internet Explorer")
 {
  headerNum = 60;
  paraNum = 100;
 }

	function maxChar(i, text, content){
		if(content == "details"){
			if(text.length > paraNum){
				text = text.substring(0, paraNum) ;
				var maxLength = text.lastIndexOf(" ");
				text = text.substring(0, maxLength);
				text = text + "...";				
				$(i).text(text);
			}
		}else{
			if(text.length > headerNum){
				text = text.substring(0, headerNum) ;
				var maxLength = text.lastIndexOf(" ");
				text = text.substring(0, maxLength);
				text = text + "...";
				$(i).text(text);
			}
		}
	}
}catch(err){}                              
                                                                                
var catArr = new Array();

$(document).ready(function(){
	$('ul.nav li:last').css('background','none');
	$('ul.footer-nav li:last a').css('border','none');
    $(".homeColumn .column:last-child").css("margin-right", "0");

	try{
		var hiddenNav = $(".hiddenNav").attr("id");
		$("ul li[rel="+hiddenNav+"] a").addClass("selected");
	}catch(err){}



	$("a.email-signup").clickShow({
		panel: 'lightbox-panel',
		close: 'close-panel',
		outSpeed: '300',
		inSpeed: '300',
		opacity: .6,
		bgcolor: '#000000',
		outerClose: true
	});
	
    try{

		$('#slides').slides({
			preload: true,
			effect: 'fade, fade',
			play: 5000,
			pause: 2500,
			hoverPause: true
		});
$('ul.pagination').css('z-index','10'); 
        var uw = $('ul.pagination').outerWidth();
        var newPos = ($('.slides_container').width() - uw)/2;
        $('ul.pagination').css('right',newPos);
	}catch(err){}
	
	try{
		if($('.search-result').length > 0){
			organizeResults();
		}else{
			if($('.searchGif').length > 0){
				//alert('NO RESULTS');
			
				
				$('#searchLoad').append('<span>No results were found. Please try another search term.</span>');
$('.searchMessage, .searchGif').hide();
			}
		}
	}catch(err){}



// REMOVE EMPTY WYSIWYG

try{

$(".wysiwyg").each(function(){  
	var alphaExp = new RegExp(/[A-Za-z0-9_]/); 
	var txt = $(this).text();
	if(alphaExp.test(txt) == false){
		$(this).hide();
	}
});

}catch(err){}

try{

$(".results").each(function(){  
	var alphaExp = new RegExp(/[A-Za-z0-9_]/); 
	var txt = $(this).text();
	if(alphaExp.test(txt) == false){
		$(this).text("No results found.");
	}
});

}catch(err){}


// Removes dropdown if an option has the value of "none"
try{
$(".skufield option").each(function(){
       if($(this).text() == "none"){
          $(this).parent().hide();
       }
});
}catch(err){}


// Removes dropdown if one option
/*
try{
if($(".skufield option").length <= 1){
          //$(".skufield").hide();
$(".skufield").appendTo("<div>"+$('skufield option').text()+"</div>")
}
}catch(err){}


if($('.sale span').text().length > 0){
  //alert('SALE');
  $('.price').children(':first-child').addClass('oldPrice');
}
*/

// Removes Item when sold out :: Pages code found in: All Collections & Categories, Art and Antiques, Product View Page

try{

$(".hiddenPrice .skuQuantity").each(function(){
if($(this).text()!="0"){
$(this).parent().parent("li").show();
}else{
$(this).parent().parent("li").remove();
}
});


$("#relatedProducts ul li.hidden").hide();

// REMOVE 4th LI's Margin
      $('ul.productList li:visible').each(function(i){
       if (i%4 == 3 )
       {
               $(this).css({"margin-right":"0","width":"185px","background-image":"none"});
       }
       
   });
}catch(err){}

// Removes You May Also like if nothing is showing

try{



}catch(err){}

if($("#relatedProducts ul li:visible").length==0 || $("#relatedProducts ul").text()<0){
$("#relatedProducts").hide();
}

// SHORTENS THE CHARACTERS DETAILS

$(".prod-info p").each(function(){
maxChar($(this),$(this).text(), "details");
});
$(".prod-info h3").each(function(){
maxChar($(this),$(this).text(), "header");
});





});
// END OF DOC.READY

/* OLD JS
function organizeResults(){
	$('.prod-category').each(function(){
		catArr[$(this).attr('rel')] = this.id;
	});


	$('.search-result').each(function(){
		var t = $(this).children('.title');
		//alert(t.html());
		$(this).children('span.category').each(function(){
			//alert($(this).text());
			var id = catArr[$(this).text()];
			//alert(id);
			$('#'+id+' div.results').append(t.clone());
		});
	});

*/



function organizeResults(){
	$('.prod-category').each(function(){
		catArr[$(this).attr('rel')] = this.id;
	});
	$('.search-result').each(function(){
		var t = $(this).children('.title');
		
        if($(this).children(".hiddenSearchItem").text() !=  "Yes"){
            if($(this).children(".soldOutSearch").children(".soldOut").attr("style") != undefined){ // Added extra check for sold out items. Task #4900
                $(this).children('span.category').each(function(){
                        var id = catArr[$(this).text()];
                        console.log($(this).text()+ id);
			$('#'+id+' div.results').append(t.clone());
		});
           } // closing extra check #4900
        }
	});

$('.searchResults').html('');
$('#displayResults').fadeIn('fast');
$('#searchLoad').delay(150).slideUp('fast').fadeOut('fast');	

}


    
