/* ********************************** */
/* Irwin Seating Global JS */
/* ********************************** */

function loadGlobals() {
	
	//NavSlider
     navSlider();
     
     //Tooltips
     toolTips();
     
     //Facebox
     $('a[rel*=facebox]').facebox();
     
     //PrettyComments
     $('.textarea').prettyComments({animate: true, maxHeight:100});
     
}
function loadHomeGlobals() {    
     //Preload Homepage Images
    preLoadHome();
    
    //Execute the slideShow  
     slideShow();
     
}
function loadConfigGlobals() {
     $(".buttons").click(function () {
		    var divname = this.alt;
		    $("#"+divname).fadeIn("slow");
		      $("#"+divname).fadeIn("slow").siblings().hide();
	 });
	 
	 $('#datepicker').datepicker({minDate: '0'});
}

// Coooookie!

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
} 
	
// Tab It Up
function tabIt(theID) {
	var tabID = "#"+theID+'-tab';
	// Main Product Detail Tabs
	if(theID == "t1" || theID == "t2" || theID == "t3" || theID == "t4" || theID == "t5") {
	createCookie('irwintab',theID);
	$('#top_tabs .tab_active').removeClass();
	}
	// Secondary Product Detail Tabs
	if(theID == "p1" || theID == "p2" || theID == "p3" || theID == "p4"){
	createCookie('irwintab2',theID);
	$('.inline_li .tab_active').removeClass();
	}
	// About Us Tabs
	if(theID == "a1" || theID == "a2" || theID == "a3"){
	createCookie('irwintab3',theID);
	$('.inline_li .tab_active').removeClass();
	}
	// FAQ Tabs
	if(theID == "f1" || theID == "f2" || theID == "f3" || theID == "f4" || theID == "f5"){
	createCookie('irwintab4',theID);
	$('.inline_li .tab_active').removeClass();
	}
	// Fabrics Tabs
	if(theID == "x2" || theID == "x3" || theID == "x4" || theID == "x5" || theID == "x6"){
	createCookie('irwintab5',theID);
	$('.inline_li .tab_active').removeClass();
	}
	
	$('#'+theID).addClass('tab_active');
	$(tabID).siblings().hide();
	$(tabID).show();
}

// Radio Button Disable
function radios(){
	var f = document.getElementsByTagName('select');
		for(var i=0;i<f.length;i++){
			f[i].setAttribute('disabled',true)
			f[i].selectedIndex=0;
		}
}
// Clear Radio Selection
function clearRadios(num){
	var ot = "#ordertrack"+num+' .bottomtrack_hide';
	var at = ".names"+num+" .buttons";
		
	$(ot).filter('.bottomtrack_hide').fadeOut();
	$(at).attr('checked', false);
	
}

// Add commas to numbers
function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

/* ********************************** */
/* Preload Homepage Images */
/* ********************************** */
function preLoadHome() {
	pic1= new Image(670,380); 
	pic1.src="../images/home/Main_1_Lucas.jpg";
	
	pic2= new Image(670,380); 
	pic2.src="../images/home/Main_2_Fellowship.jpg";
	
	pic3= new Image(670,380); 
	pic3.src="../images/home/Main_3_Strathmore.jpg";
	
	pic4= new Image(670,380); 
	pic4.src="../images/home/Main_4_CoopArts.jpg";
	
	pic5= new Image(670,380); 
	pic5.src="../images/home/Main_5_FerrisHS.jpg";
	
	pic6= new Image(670,380); 
	pic6.src="../images/home/Main_6_Yale.jpg";
	
	pic7= new Image(670,380); 
	pic7.src="../images/home/Main_7_Marcus.jpg";
	
	pic8= new Image(670,380); 
	pic8.src="../images/home/Main_8_Chaifetz.jpg";
	
	pic9= new Image(670,380); 
	pic9.src="../images/home/Main_9_LafayettHS.jpg";
	
	pic10= new Image(670,380); 
	pic10.src="../images/home/Main_10_OSU.jpg";
	
	pic11= new Image(670,380); 
	pic11.src="../images/home/Main_11_Yankee.jpg";
	
	pic12= new Image(670,380); 
	pic12.src="../images/home/Main_12_UofM.jpg";
	
	pic13= new Image(670,380); 
	pic13.src="../images/home/Main_13_UofM.jpg";
}

// Nav Menu BG
	//pic14= new Image(670,380); 
	//pic14.src="../images/nav_menu_bg.jpg";

/* ********************************** */
/* Navigation Slidedown Menu */
/* ********************************** */ 

function navSlider() {
    // Nav Slider
    var toggle = "first";
    var down = "no";
    
    $('#nav_facility').css("display", "none");
    $('#nav_type').css("display", "none");
        
	$('#nav_items #facility').mouseover(function(){
		if(down == "no") {
	    	$(this).addClass("nav_hovered");
	    }
	});
	
	$('#nav_items #facility').hover(function(){
		if(toggle == "first") {
			toggle = "on";
			setTimeout ( "$('#nav_type').css('display', 'none')", 500);
			$('#nav_items #type').removeClass("nav_clicked");
			down1 = "no";
			toggle1 = "first";
		}else{
			toggle = "off";
		}
		if(toggle == "off"){
			$('#nav_facility').slideUp();	
			setTimeout ( "$('#nav_items #facility').removeClass('nav_clicked')", 400);
			down = "no";
			toggle = "first";
		}
		if(toggle == "on") {
			$(this).removeClass("nav_hovered");
			$(this).addClass("nav_clicked");
			$('#nav_type').css("display", "none");
			$('#nav_facility').slideDown();
			down = "yes";
		}
	});
	
	$('#nav_items #facility').mouseout(function(){
		if(down == "no") {
			$(this).removeClass("nav_hovered");
			$('#nav_facility').slideUp();
		}
		
		if(down == "yes") {
			$(this).removeClass();
			$(this).addClass("nav_clicked");
		}
	});
	
	var toggle1 = "first";
    var down1 = "no";
        
	$('#nav_items #type').mouseover(function(){
		if(down1 == "no") {
	    	$(this).addClass("nav_hovered");
	    }
	});
	
	$('#nav_items #type').hover(function(){
		if(toggle1 == "first") {
			toggle1 = "on";
			$('#nav_facility').css('display', 'none');
			$('#nav_items #facility').removeClass("nav_clicked");
			down = "no";
			toggle = "first";
		}else{
			toggle1 = "off";
		}
		if(toggle1 == "off"){
			$('#nav_type').slideUp();	
			setTimeout ( "$('#nav_items #type').removeClass('nav_clicked')", 400);
			down1 = "no";
			toggle1 = "first";
		}
		if(toggle1 == "on") {
			$(this).removeClass("nav_hovered");
			$(this).addClass("nav_clicked");
			$('#nav_type').slideDown();
			down1 = "yes";
		}
	});
	
	$('#nav_items #type').mouseout(function(){
		if(down1 == "no") {
			$(this).removeClass("nav_hovered");
			$('#nav_type').slideUp();
		}
		
		if(down1 == "yes") {
			$(this).removeClass();
			$(this).addClass("nav_clicked");
		}
	});
}

/* ********************************** */
/* Slideshow */
/* ********************************** */

function slideShow() {  
   
     //Set the opacity of all images to 0  
     $('#gallery a').css({opacity: 0.0});  
       
     //Get the first image and display it (set it to full opacity)  
     $('#gallery a:first').css({opacity: 1.0});  
       
     //Set the caption background to semi-transparent  
     $('#gallery .caption').css({opacity: 0.7});  
   
     //Resize the width of the caption according to the image width  
     $('#gallery .caption').css({width: $('#gallery a').find('img').css('width')});  
       
     //Get the caption of the first image from REL attribute and display it  
     $('#gallery .content').html($('#gallery a:first').find('img').attr('alt'))  
     .animate({opacity: 0.7}, 400);  
       
     //Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds  
     setInterval('gallery()',6000);  
       
 }
  
function gallery() {  
       
     //if no IMGs have the show class, grab the first image  
     var current = ($('#gallery a.show')?  $('#gallery a.show') : $('#gallery a:first'));  
   
     //Get next image, if it reached the end of the slideshow, rotate it back to the first image  
     var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery a:first') :current.next()) : $('#gallery a:first'));     
       
     //Get next image caption  
     var caption = next.find('img').attr('alt');   
       
     //Set the fade in effect for the next image, show class has higher z-index  
     next.css({opacity: 0.0})  
     .addClass('show')  
     .animate({opacity: 1.0}, 1000);  
   
     //Hide the current image  
     current.animate({opacity: 0.0}, 1000)  
     .removeClass('show');  
       
     //Set the opacity to 0 and height to 1px  
     $('#gallery .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });   
       
     //Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect  
     $('#gallery .caption').animate({opacity: 0.7},100 ).animate({height: '100px'},500 );  
       
     //Display the content  
     $('#gallery .content').html(caption);  
           
 }

/* ********************************** */
/* Tooltips */
/* ********************************** */

function toolTips() {
	 $(".tooltips").hover(
        function() { $(this).contents("span:last-child").css({ display: "block" }); },
        function() { $(this).contents("span:last-child").css({ display: "none" }); }
   );
    $(".tooltips").mousemove(function(e) {
        var mousex = e.pageX + 10;
        var mousey = e.pageY + 5;
        $(this).contents("span:last-child").css({  top: mousey, left: mousex });
    });
}

/* ********************************** */
/* jPrompt Product Info */
/* ********************************** */

function productInfo(code){
	
	// Start Over Dialog
	if(code == "1") {
		$.alerts.okButton = 'Close';
		$.alerts.cancelButton = 'Cancel';
		
		jAlert('Here is some product info.', 'Product Info'
		);
	}
	
}

/* ********************************** */
/* jAlert Confirmation */
/* ********************************** */

function confirmation(code, page){
	
	// Start Over Dialog
	if(code == "1") {
		$.alerts.okButton = 'Start Over';
		$.alerts.cancelButton = 'Cancel';
		
		jConfirm('Are you sure you want to start over from <strong>Step 1</strong>?', 'Confirmation Needed', function(r) {
			if(r){response='true';}
			if(response=='true')
				{location.href='back.php?startover=1'};
			}
		);
	}
	
	// Go Back Dialog
	if(code == "2") {
		$.alerts.okButton = 'Go Back';
		$.alerts.cancelButton = 'Cancel';
		
		var response = "false"
		
		jConfirm('Are you sure you want to go back?', 'Confirmation Needed', function(r) {
			if(r){response='true';}
			if(response=='true')
				{location.href=page};
			}
		);
	}
	
}

/* ********************************** */
/* jAlert Errors */
/* ********************************** */

function errors(code){
	// Error 1: Something Went Wrong. Start Over.
	if(code == 1) {
		$.alerts.okButton = 'OK';
		
		jAlert('We\'re sorry. You must select a Platform first.', 'Error', function(r) {
			if(r){response='true';}
			if(response=='true')
				{return false;};
			}
		);
	}
	
	// Error 2: Absolutely Nothing Selected
	if(code == 2) {
		$.alerts.okButton = 'OK';
		
		jAlert('Please make a selection.', 'Error', function(r) {
			if(r){response='true';}
			if(response=='true')
				{return false;};
			}
		);
	}
	
	// Error 3: No Option Selected
	if(code == 3) {
		$.alerts.okButton = 'OK';
		
		jAlert('Please choose an option.', 'Error', function(r) {
			if(r){response='true';}
			if(response=='true')
				{return false;};
			}
		);
	}
	
	// Error 4: Start Over
	if(code == 4) {
		$.alerts.okButton = 'OK';
		
		jAlert('Something went wrong and we couldn\'t process your order.', 'Error', function(r) {
			if(r){response='true';}
			if(response=='true')
				{location.href='back.php?startover=1'};
			}
		);
	}
	
	// Error 5: No Option Selected
	if(code == 5) {
		$.alerts.okButton = 'OK';
		
		jAlert('Please choose an armrest.', 'Error', function(r) {
			if(r){response='true';}
			if(response=='true')
				{return false;};
			}
		);
	}
}

// jQuery Alert Dialogs Plugin
//
// Version 1.1
//
// Cory S.N. LaViska
// A Beautiful Site (http://abeautifulsite.net/)
// 14 May 2009
//
// Visit http://abeautifulsite.net/notebook/87 for more information
//
// Usage:
//		jAlert( message, [title, callback] )
//		jConfirm( message, [title, callback] )
//		jPrompt( message, [value, title, callback] )
// 
// History:
//
//		1.00 - Released (29 December 2008)
//
//		1.01 - Fixed bug where unbinding would destroy all resize events
//
// License:
// 
// This plugin is dual-licensed under the GNU General Public License and the MIT License and
// is copyright 2008 A Beautiful Site, LLC. 
//
(function($) {
	
	$.alerts = {
		
		// These properties can be read/written by accessing $.alerts.propertyName from your scripts at any time
		
		verticalOffset: -75,                // vertical offset of the dialog from center screen, in pixels
		horizontalOffset: 0,                // horizontal offset of the dialog from center screen, in pixels/
		repositionOnResize: true,           // re-centers the dialog on window resize
		overlayOpacity: .01,                // transparency level of overlay
		overlayColor: '#FFF',               // base color of overlay
		draggable: true,                    // make the dialogs draggable (requires UI Draggables plugin)
		okButton: '&nbsp;OK&nbsp;',         // text for the OK button
		cancelButton: '&nbsp;Cancel&nbsp;', // text for the Cancel button
		dialogClass: null,                  // if specified, this class will be applied to all dialogs
		
		// Public methods
		
		alert: function(message, title, callback) {
			if( title == null ) title = 'Alert';
			$.alerts._show(title, message, null, 'alert', function(result) {
				if( callback ) callback(result);
			});
		},
		
		confirm: function(message, title, callback) {
			if( title == null ) title = 'Confirm';
			$.alerts._show(title, message, null, 'confirm', function(result) {
				if( callback ) callback(result);
			});
		},
			
		prompt: function(message, value, title, callback) {
			if( title == null ) title = 'Prompt';
			$.alerts._show(title, message, value, 'prompt', function(result) {
				if( callback ) callback(result);
			});
		},
		
		// Private methods
		
		_show: function(title, msg, value, type, callback) {
			
			$.alerts._hide();
			$.alerts._overlay('show');
			
			$("BODY").append(
			  '<div id="popup_container">' +
			    '<h1 id="popup_title"></h1>' +
			    '<div id="popup_content">' +
			      '<div id="popup_message"></div>' +
				'</div>' +
			  '</div>');
			
			if( $.alerts.dialogClass ) $("#popup_container").addClass($.alerts.dialogClass);
			
			// IE6 Fix
			var pos = ($.browser.msie && parseInt($.browser.version) <= 6 ) ? 'absolute' : 'fixed'; 
			
			$("#popup_container").css({
				position: pos,
				zIndex: 99999,
				padding: 0,
				margin: 0
			});
			
			$("#popup_title").text(title);
			$("#popup_content").addClass(type);
			$("#popup_message").text(msg);
			$("#popup_message").html( $("#popup_message").text().replace(/\n/g, '<br />') );
			
			$("#popup_container").css({
				minWidth: $("#popup_container").outerWidth(),
				maxWidth: $("#popup_container").outerWidth()
			});
			
			$.alerts._reposition();
			$.alerts._maintainPosition(true);
			
			switch( type ) {
				case 'alert':
					$("#popup_message").after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /></div>');
					$("#popup_ok").click( function() {
						$.alerts._hide();
						callback(true);
					});
					$("#popup_ok").focus().keypress( function(e) {
						if( e.keyCode == 13 || e.keyCode == 27 ) $("#popup_ok").trigger('click');
					});
				break;
				case 'confirm':
					$("#popup_message").after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /> <input type="button" value="' + $.alerts.cancelButton + '" id="popup_cancel" /></div>');
					$("#popup_ok").click( function() {
						$.alerts._hide();
						if( callback ) callback(true);
					});
					$("#popup_cancel").click( function() {
						$.alerts._hide();
						if( callback ) callback(false);
					});
					$("#popup_ok").focus();
					$("#popup_ok, #popup_cancel").keypress( function(e) {
						if( e.keyCode == 13 ) $("#popup_ok").trigger('click');
						if( e.keyCode == 27 ) $("#popup_cancel").trigger('click');
					});
				break;
				case 'prompt':
					$("#popup_message").append('<br /><input type="text" size="30" id="popup_prompt" />').after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /> <input type="button" value="' + $.alerts.cancelButton + '" id="popup_cancel" /></div>');
					$("#popup_prompt").width( $("#popup_message").width() );
					$("#popup_ok").click( function() {
						var val = $("#popup_prompt").val();
						$.alerts._hide();
						if( callback ) callback( val );
					});
					$("#popup_cancel").click( function() {
						$.alerts._hide();
						if( callback ) callback( null );
					});
					$("#popup_prompt, #popup_ok, #popup_cancel").keypress( function(e) {
						if( e.keyCode == 13 ) $("#popup_ok").trigger('click');
						if( e.keyCode == 27 ) $("#popup_cancel").trigger('click');
					});
					if( value ) $("#popup_prompt").val(value);
					$("#popup_prompt").focus().select();
				break;
			}
			
			// Make draggable
			if( $.alerts.draggable ) {
				try {
					$("#popup_container").draggable({ handle: $("#popup_title") });
					$("#popup_title").css({ cursor: 'move' });
				} catch(e) { /* requires jQuery UI draggables */ }
			}
		},
		
		_hide: function() {
			$("#popup_container").remove();
			$.alerts._overlay('hide');
			$.alerts._maintainPosition(false);
		},
		
		_overlay: function(status) {
			switch( status ) {
				case 'show':
					$.alerts._overlay('hide');
					$("BODY").append('<div id="popup_overlay"></div>');
					$("#popup_overlay").css({
						position: 'absolute',
						zIndex: 99998,
						top: '0px',
						left: '0px',
						width: '100%',
						height: $(document).height(),
						background: $.alerts.overlayColor,
						opacity: $.alerts.overlayOpacity
					});
				break;
				case 'hide':
					$("#popup_overlay").remove();
				break;
			}
		},
		
		_reposition: function() {
			var top = (($(window).height() / 2) - ($("#popup_container").outerHeight() / 2)) + $.alerts.verticalOffset;
			var left = (($(window).width() / 2) - ($("#popup_container").outerWidth() / 2)) + $.alerts.horizontalOffset;
			if( top < 0 ) top = 0;
			if( left < 0 ) left = 0;
			
			// IE6 fix
			if( $.browser.msie && parseInt($.browser.version) <= 6 ) top = top + $(window).scrollTop();
			
			$("#popup_container").css({
				top: top + 'px',
				left: left + 'px'
			});
			$("#popup_overlay").height( $(document).height() );
		},
		
		_maintainPosition: function(status) {
			if( $.alerts.repositionOnResize ) {
				switch(status) {
					case true:
						$(window).bind('resize', $.alerts._reposition);
					break;
					case false:
						$(window).unbind('resize', $.alerts._reposition);
					break;
				}
			}
		}
		
	}
	
	// Shortuct functions
	jAlert = function(message, title, callback) {
		$.alerts.alert(message, title, callback);
	}
	
	jConfirm = function(message, title, callback) {
		$.alerts.confirm(message, title, callback);
	};
		
	jPrompt = function(message, value, title, callback) {
		$.alerts.prompt(message, value, title, callback);
	};
	
})(jQuery);

/*
 * Facebox (for jQuery)
 * version: 1.2 (05/05/2008)
 * @requires jQuery v1.2 or later
 *
 * Examples at http://famspam.com/facebox/
 *
 * Licensed under the MIT:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Copyright 2007, 2008 Chris Wanstrath [ chris@ozmm.org ]
 *
 * Usage:
 *  
 *  jQuery(document).ready(function() {
 *    jQuery('a[rel*=facebox]').facebox() 
 *  })
 *
 *  <a href="#terms" rel="">Terms</a>
 *    Loads the #terms div in the box
 *
 *  <a href="terms.html" rel="facebox">Terms</a>
 *    Loads the terms.html page in the box
 *
 *  <a href="terms.png" rel="facebox">Terms</a>
 *    Loads the terms.png image in the box
 *
 *
 *  You can also use it programmatically:
 * 
 *    jQuery.facebox('some html')
 *
 *  The above will open a facebox with "some html" as the content.
 *    
 *    jQuery.facebox(function($) { 
 *      $.get('blah.html', function(data) { $.facebox(data) })
 *    })
 *
 *  The above will show a loading screen before the passed function is called,
 *  allowing for a better ajaxy experience.
 *
 *  The facebox function can also display an ajax page or image:
 *  
 *    jQuery.facebox({ ajax: 'remote.html' })
 *    jQuery.facebox({ image: 'dude.jpg' })
 *
 *  Want to close the facebox?  Trigger the 'close.facebox' document event:
 *
 *    jQuery(document).trigger('close.facebox')
 *
 *  Facebox also has a bunch of other hooks:
 *
 *    loading.facebox
 *    beforeReveal.facebox
 *    reveal.facebox (aliased as 'afterReveal.facebox')
 *    init.facebox
 *
 *  Simply bind a function to any of these hooks:
 *
 *   $(document).bind('reveal.facebox', function() { ...stuff to do after the facebox and contents are revealed... })
 *
 */
(function($) {
  $.facebox = function(data, klass) {
    $.facebox.init()
    $.facebox.loading()
    $.isFunction(data) ? data.call($) : $.facebox.reveal(data, klass)   
  }
  $(document).ready(function() {
  	$('a[rel*=facebox]').click(function() {
		var caption = $(this).attr('title');
		$('<div class="caption">' + caption + '</div>').insertAfter($
		('.footer')).show()
	});
  });

$(document).bind('close.facebox', function() {
$('.caption').remove();

});

  /*
   * Public, $.facebox methods
   */

  $.extend($.facebox, {
    settings: {
      opacity      : 0,
      overlay      : true,
      loadingImage : 'images/loading.gif',
      closeImage   : 'images/closelabel.gif',
      imageTypes   : [ 'png', 'jpg', 'jpeg', 'gif' ],
      faceboxHtml  : '\
    <div id="facebox" style="display:none;"> \
      <div class="popup"> \
        <table> \
          <tbody> \
            <tr> \
              <td class="tl"/><td class="b"/><td class="tr"/> \
            </tr> \
            <tr> \
              <td class="b"/> \
              <td class="body"> \
                <div class="content"> \
                </div> \
                <div class="footer"> \
                  <a href="#" class="close"> \
                    <img src="images/closelabel.gif" title="close" class="close_image" /> \
                  </a> \
                </div> \
              </td> \
              <td class="b"/> \
            </tr> \
            <tr> \
              <td class="bl"/><td class="b"/><td class="br"/> \
            </tr> \
          </tbody> \
        </table> \
      </div> \
    </div>'
    },

    loading: function() {
      init()
      if ($('#facebox .loading').length == 1) return true
      showOverlay()

      $('#facebox .content').empty()
      $('#facebox .body').children().hide().end().
        append('<div class="loading"><img src="'+$.facebox.settings.loadingImage+'"/></div>')

      $('#facebox').css({
        top:	getPageScroll()[1],
        left:	385.5
      }).show()
      
      /*$('#facebox').css({
  top:    getPageScroll()[1] + (getPageHeight() / 10),
  left:   ($(window).width() - $('#facebox').width()) / 2
}).show()*/

      $(document).bind('keydown.facebox', function(e) {
        if (e.keyCode == 27) $.facebox.close()
        return true
      })
      $(document).trigger('loading.facebox')
    },

    reveal: function(data, klass) {
      $(document).trigger('beforeReveal.facebox')
      if (klass) $('#facebox .content').addClass(klass)
      $('#facebox .content').append(data)
      $('#facebox .loading').remove()
      $('#facebox .body').children().fadeIn('normal')
      $('#facebox').css('left', $(window).width() / 2 - ($('#facebox table').width() / 2))
      $(document).trigger('reveal.facebox').trigger('afterReveal.facebox')
    },

    close: function() {
      $(document).trigger('close.facebox')
      return false
    }
  })

  /*
   * Public, $.fn methods
   */

  $.fn.facebox = function(settings) {
    init(settings)

    function clickHandler() {
      $.facebox.loading(true)

      // support for rel="facebox.inline_popup" syntax, to add a class
      // also supports deprecated "facebox[.inline_popup]" syntax
      var klass = this.rel.match(/facebox\[?\.(\w+)\]?/)
      if (klass) klass = klass[1]

      fillFaceboxFromHref(this.href, klass)
      return false
    }

    return this.click(clickHandler)
  }

  /*
   * Private methods
   */

  // called one time to setup facebox on this page
  function init(settings) {
    if ($.facebox.settings.inited) return true
    else $.facebox.settings.inited = true

    $(document).trigger('init.facebox')
    makeCompatible()

    var imageTypes = $.facebox.settings.imageTypes.join('|')
    $.facebox.settings.imageTypesRegexp = new RegExp('\.' + imageTypes + '$', 'i')

    if (settings) $.extend($.facebox.settings, settings)
    $('body').append($.facebox.settings.faceboxHtml)

    var preload = [ new Image(), new Image() ]
    preload[0].src = $.facebox.settings.closeImage
    preload[1].src = $.facebox.settings.loadingImage

    $('#facebox').find('.b:first, .bl, .br, .tl, .tr').each(function() {
      preload.push(new Image())
      preload.slice(-1).src = $(this).css('background-image').replace(/url\((.+)\)/, '$1')
    })

    $('#facebox .close').click($.facebox.close)
    $('#facebox .close_image').attr('src', $.facebox.settings.closeImage)
  }
  
  // getPageScroll() by quirksmode.com
  function getPageScroll() {
    var xScroll, yScroll;
    if (self.pageYOffset) {
      yScroll = self.pageYOffset;
      xScroll = self.pageXOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
      yScroll = document.documentElement.scrollTop;
      xScroll = document.documentElement.scrollLeft;
    } else if (document.body) {// all other Explorers
      yScroll = document.body.scrollTop;
      xScroll = document.body.scrollLeft;	
    }
    return new Array(xScroll,yScroll) 
  }

  // Adapted from getPageSize() by quirksmode.com
  function getPageHeight() {
    var windowHeight
    if (self.innerHeight) {	// all except Explorer
      windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
      windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
      windowHeight = document.body.clientHeight;
    }	
    return windowHeight
  }

  // Backwards compatibility
  function makeCompatible() {
    var $s = $.facebox.settings

    $s.loadingImage = $s.loading_image || $s.loadingImage
    $s.closeImage = $s.close_image || $s.closeImage
    $s.imageTypes = $s.image_types || $s.imageTypes
    $s.faceboxHtml = $s.facebox_html || $s.faceboxHtml
  }

  // Figures out what you want to display and displays it
  // formats are:
  //     div: #id
  //   image: blah.extension
  //    ajax: anything else
  function fillFaceboxFromHref(href, klass) {
    // div
    if (href.match(/#/)) {
      var url    = window.location.href.split('#')[0]
      var target = href.replace(url,'')
      $.facebox.reveal($(target).clone().show(), klass)

    // image
    } else if (href.match($.facebox.settings.imageTypesRegexp)) {
      fillFaceboxFromImage(href, klass)
    // ajax
    } else {
      fillFaceboxFromAjax(href, klass)
    }
  }

  function fillFaceboxFromImage(href, klass) {
    var image = new Image()
    image.onload = function() {
      $.facebox.reveal('<div class="image"><img src="' + image.src + '" /></div>', klass)
    }
    image.src = href
  }

  function fillFaceboxFromAjax(href, klass) {
    $.get(href, function(data) { $.facebox.reveal(data, klass) })
  }

  function skipOverlay() {
    return $.facebox.settings.overlay == false || $.facebox.settings.opacity === null 
  }

  function showOverlay() {
    if (skipOverlay()) return

    if ($('facebox_overlay').length == 0) 
      $("body").append('<div id="facebox_overlay" class="facebox_hide"></div>')

    $('#facebox_overlay').hide().addClass("facebox_overlayBG")
      .css('opacity', $.facebox.settings.opacity)
      .click(function() { $(document).trigger('close.facebox') })
      .fadeIn(200)
    return false
  }

  function hideOverlay() {
    if (skipOverlay()) return

    $('#facebox_overlay').fadeOut(200, function(){
      $("#facebox_overlay").removeClass("facebox_overlayBG")
      $("#facebox_overlay").addClass("facebox_hide") 
      $("#facebox_overlay").remove()
    })
    
    return false
  }

  /*
   * Bindings
   */

  $(document).bind('close.facebox', function() {
    $(document).unbind('keydown.facebox')
    $('#facebox').fadeOut(function() {
      $('#facebox .content').removeClass().addClass('content')
      hideOverlay()
      $('#facebox .loading').remove()
    })
  })

})(jQuery);

/* ------------------------------------------------------------------------
	Pretty Comments
	
	Developped By: Stephane Caron (http://www.no-margin-for-errors.com)
	Inspired By: The facebook textarea :)
	Version: 1.4
	
	Copyright: Feel free to redistribute the script/modify it, as
			   long as you leave my infos at the top.
------------------------------------------------------------------------- */

	$.fn.prettyComments = function(settings) {
		settings = jQuery.extend({
					animate: false, /* If you set it to true, cursor will dissapear in FF3 */
					animationSpeed: 'fast', /* fast/slow/normal */
					maxHeight : 500,
					alreadyAnimated: false, /* DONT CHANGE */
					init: true /* DONT CHANGE */
				}, settings);

		// Create the div in which the content will be copied
		$('body').append('<div id="comment_hidden"></div>');

		var setCSS = function(which){
			// Init the div for the current textarea
			$("#comment_hidden").css({
				'position':'absolute',
				'top': -10000,
				'left': -10000,
				'width': $(which).width(),
				'min-height': $(which).height(),
				'font-family': $(which).css('font-family'),
				'font-size': $(which).css('font-size'),
				'line-height': $(which).css('line-height')
			});
			
			if($.browser.msie && parseFloat($.browser.version) < 7){
				$("#comment_hidden").css('height',$(which).height());
			};
		};
		
		var copyContent = function(which){
			// Convert the line feeds into BRs
			theValue = $(which).attr('value') || "";
			theValue = theValue.replace(/\n/g,'<br />');
			
			$("#comment_hidden").html(theValue + '<br />');
			
			if(!settings.init){
				if($("#comment_hidden").height() > $(which).height()){
					if($('#comment_hidden').height() > settings.maxHeight){
						$(which).css('overflow-y','scroll');
					}else{
						$(which).css('overflow-y','hidden');
						expand(which);
					};
				}else if($("#comment_hidden").height() < $(which).height()){
					if($('#comment_hidden').height() > settings.maxHeight){
						$(which).css('overflow-y','scroll');
					}else{
						$(which).css('overflow-y','hidden');
						shrink(which);
					};
				};
			};
		};
		
		var expand = function(which){
			if(settings.animate && !settings.alreadyAnimated){
				settings.alreadyAnimated = true;
				$(which).animate({'height':$("#comment_hidden").height()},settings.animationSpeed,function(){
					settings.alreadyAnimated = false;
				});
			}else if(!settings.animate && !settings.alreadyAnimated){
				$(which).height($("#comment_hidden").height());
			};
		};
		
		var shrink = function(which){
			if(settings.animate && !settings.alreadyAnimated){
				settings.alreadyAnimated = true;
				$(which).animate({'height':$("#comment_hidden").height()},settings.animationSpeed,function(){
					settings.alreadyAnimated = false;
				});
			}else{
				$(which).height($("#comment_hidden").height());
			};
		};
		
		$(this).each(function(){
			$(this).css({
				'overflow':'hidden'
			})
			.bind('keyup',function(){
				copyContent($(this));
			});
			
			// Make sure all the content in the textarea is visible
			setCSS(this);
			copyContent($(this));
			
			if($("#comment_hidden").height() > settings.maxHeight){
				$(this).css({
					'overflow-y':'scroll',
					'height':settings.maxHeight
				});
			}else{
				$(this).height($("#comment_hidden").height());
			};
			
			settings.init = false;
		});
	};
	
	
/***************************/
//@Author: Adrian "yEnS" Mato Gondelle & Ivan Guardado Castro
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

$(document).ready(function(){
	//global vars
	var searchBoxes = $(".text");
	var searchBox1 = $("#search");
	var searchBox1Default = "Search by Product Keyword";
	
	//Searchbox2 show/hide default text if needed
	searchBox1.focus(function(){
		if($(this).attr("value") == searchBox1Default) $(this).attr("value", "");
	});
	searchBox1.blur(function(){
		if($(this).attr("value") == "") $(this).attr("value", searchBox1Default);
	});
});
