// JavaScript Document
function implode (glue, pieces) {
    // Joins array elements placing glue string between items and return one string  
    // 
    // version: 1103.1210
    // discuss at: http://phpjs.org/functions/implode
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Waldo Malqui Silva
    // +   improved by: Itsacon (http://www.itsacon.net/)
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: implode(' ', ['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: 'Kevin van Zonneveld'
    // *     example 2: implode(' ', {first:'Kevin', last: 'van Zonneveld'});
    // *     returns 2: 'Kevin van Zonneveld'
    var i = '',
        retVal = '',
        tGlue = '';
    if (arguments.length === 1) {
        pieces = glue;
        glue = '';
    }
    if (typeof(pieces) === 'object') {
        if (pieces instanceof Array) {
            return pieces.join(glue);
        } else {
            for (i in pieces) {
                retVal += tGlue + pieces[i];
                tGlue = glue;
            }
            return retVal;
        }
    } else {
        return pieces;
    }
}

function explode(item,delimiter) { 
	tempArray=new Array(1); 
	var Count=0; 
	var tempString=new String(item);
	
	while (tempString.indexOf(delimiter)>0) { 
		tempArray[Count]=tempString.substr(0,tempString.indexOf(delimiter)); 
		tempString=tempString.substr(tempString.indexOf(delimiter)+1,tempString.length-tempString.indexOf(delimiter)+1); 
		Count=Count+1 
	}
	
	tempArray[Count]=tempString; 
	return tempArray; 
}


function stripeDisplayTables(){
	
	//stripe all of the displayTables
	$('.displayTable').each(function(){

		if(!$(this).hasClass('colorTable'))
		{
			$('.displayTable tr').each(function(){
										  
				$(this).removeClass('row0');
				$(this).removeClass('row1');
				
			});
			
			$('.displayTable tr:nth-child(even)').each(function(){
				
				$(this).addClass('row0');
				
			});
			
			$('.displayTable tr:nth-child(odd)').each(function(){
				
				$(this).addClass('row1');
				
			});
			
			
		}
	
	});
	
}

function formatLeftBar()
{
	//if the leftbar exists
	if($('#leftBar').attr('id'))
	{	
		$('#container').css('padding-bottom', 0);
		var lbWidth = $('#leftBar').width();
		var paddingBottom = $('#leftBar').parent().css('padding-bottom');
		paddingBottom = paddingBottom.substring(0, paddingBottom.length - 2); //eliminate the 'px' on the end
		var parentHeight = $('#leftBar').parent().height();
		parentHeight = (parentHeight * 1) + (paddingBottom * 1);
		var leftMargin = 10;
		
		if(parentHeight < $('#leftBar').height()) parentHeight = $('#leftBar').height();
		
		$('#leftBar').css({ minHeight:parentHeight, paddingLeft:leftMargin, marginLeft:0, marginBottom:-paddingBottom });
		//$('#leftBar').css({ height:'auto' });
	}
}

/* 
-----------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------


     Global Document.Ready


-----------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------
*/

$(document).ready(function(){ 
	
	//by using window.load, we can get a more accurate reading of DOM elements
	//things like height, width, etc. aren't properly calculated until the window loads
	
	$(window).load(function() {
		
		$("#navigation a.mainLink").each(function(){
			
			//if this link goes nowhere...
			if($(this).attr('href') == '#')
			{
				//return false so the page doesn't refresh 
				//when the link is clicked
				$(this).click(function(){return false;});
			}
		});
		
		if($.browser.msie)
		{
			//if we're using Internet Explorer, superfish the navigation.
			//otherwise, use the more attractive navigation (which bugs up in IE)
			$("#header #navigation").superfish(); 
		}
		else
		{
			$("#header #navigation li.topLI").hover(function(){
				
				var topLI = $(this);
				var mainLink = $(this).find("a.mainLink");
				var subNav = $(this).find(".subNav");
				
				//alert($(subNav).height());
				$(topLI).css({ height:$(subNav).height() + 20 });
				$(mainLink).addClass("active");
				$(subNav).show();
			
			}, function(){
				
				var topLI = $(this);
				var mainLink = $(this).find("a.mainLink");
				var subNav = $(this).find(".subNav");
				
				$(topLI).css({ height:'auto' });
				$(mainLink).removeClass("active");
				$(subNav).hide();
			
			});
			
			$("#header #navigation li.subLI").hover(function(){
				
				var topLI = $(this).parent().parent();
				var subLI = $(this);
				var subLink = $(this).find("a.subLink");
				var subNav = $(this).find("ul");
				
				$(topLI).css({ height:$(topLI).height() + $(subNav).height() });
				$(subLink).addClass("active");
				$(subNav).show();
			
			}, function(){
				
				var topLI = $(this).parent().parent();
				var subLI = $(this);
				var subLink = $(this).find("a.subLink");
				var subNav = $(this).find("ul");
				
				$(topLI).css({ height:$(topLI).height() - $(subNav).height() });
				$(subLink).removeClass("active");
				$(subNav).hide();
			
			});
		}
		
		//format all of the blueButtons
		$('.blueButton').each(function(){
			
			//append the image at the end of the text
			$(this).append('&nbsp;<img src="/images/white-arrow.png" alt="&gt;" />');
			
			//vertically align all text
			var thisHeight = $(this).height();
			var desiredHeight = 75;
			var padding = (desiredHeight - thisHeight) / 2;
			
			$(this).css({ paddingTop:padding, paddingBottom:padding });
								 
		});
		
		//stripe all of the displayTables
		stripeDisplayTables();
		
		//fade in the message box
		$(document).oneTime(50, function(){
									   
			$('#messageBox').fadeIn('slow');
			
			$('#messageBox').oneTime(8000, function(){
				$(this).fadeOut('slow');
			});
		
		});
		
		//format the leftBar height and bring it to the very edge of the page
		formatLeftBar();
		
		//View Colors for Product Page
		$('.viewColors').click(function(){
		
			var thisID = $(this).attr('id');
			thisID = thisID.replace('viewColors_','');
			
			var colorDiv = $('#showColors_' + thisID);
			var colorTd = $('#showColors_' + thisID + '_td');
			
			if($(colorDiv).css('display') == 'none'){
				
				$(colorDiv).slideDown(200);
				
			}else{
				
				$(colorDiv).slideUp(200);
			}
		});
	
	});
   $('a[rel=htmltooltip]').tooltip({
	   showURL: false,
	   track: true,
	   fade: 250,
	   delay:0,
	   opacity: 1
   });
}); 

function is_int(value){
  if((parseFloat(value) == parseInt(value)) && !isNaN(value)){
      return true;
  } else {
      return false;
  }
}
