/*  SEARCH BOX CLEAR Copyright (c) 2008 Brandon Aaron (http://brandonaaron.net)
  * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
  * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
  *
  * $LastChangedDate$
  * $Rev$
  *
  * Version 0.2
  *
  * Usage:
  *   $("input[name=q]")
  *      .val("Search")    // set an initial value if it doesn't already exist
  *      .clearonfocus();  // prepare the element for clearing on focus
  */
 jQuery.fn.clearonfocus = function() {
     return this
         .bind('focus', function() {
             // Set the default value if it isn't set
             if ( !this.defaultValue ) this.defaultValue = this.value;
             // Check to see if the value is different
             if ( this.defaultValue && this.defaultValue != this.value ) return;
             // It isn't, so remove the text from the input
             this.value = '';
         })
         .bind('blur', function() {
             // If the value is blank, return it to the defaultValue
             if ( this.value.match(/^\s*$/) )
                 this.value = this.defaultValue;
         });
 };

$(document).ready(function(){
	$('#s').val("Category Search").clearonfocus();
		$('#luser_name').val("User Name").clearonfocus();
			$('#lpassword').val("Password").clearonfocus();
});


/* DROP DOWN MENU - The following 2 items call the dropdown menu behaviors. First up is a function that expands the dropdown to the largest sub item. Must come first. After that is the SuperFish menu call itself. */
$(document).ready(function(){ 
        $("ul.sf-menu").supersubs({ 
            minWidth:    9,   // minimum width of sub-menus in em units 
            maxWidth:    27,   // maximum width of sub-menus in em units 
            extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
                               // due to slight rounding differences and font-family 
        }).superfish();  // call supersubs first, then superfish, so that subs are 
                         // not display:none when measuring. Call before initialising 
                         // containing tabs for same reason. 
    }); 

jQuery(function(){
	jQuery('ul.sf-menu').superfish();
});


/* IMAGE SWAPS  example of usage: give img the .buttonswap class and make sure to get the on (mouse on) and off (mouse off) */
$(document).ready(function(){
	$(".buttonSwap").hover(
	 function()
	 {this.src = this.src.replace("_off","_on");},
	 function()
	 {this.src = this.src.replace("_on","_off");}
	);
});


/* TABLE ZEBRA STRIPE */
$(document).ready(function(){
	$(".equipmentTable tr:nth-child(even)").addClass("alt");
});



/* PRODUCT LIST ZEBRA STRIPE */
$(document).ready(function(){
	$(".productList li:nth-child(even)").addClass("alt");
});


/* TRANSLATION CODE */
$(document).ready(function(){ //when DOM is ready 
 
  $.translate(function(){  //when the Google Language API is loaded 
   
	function translateTo( destLang ){ //this can be declared in the global scope too if you need it somewhere else 
        $('body').translate( 'english', destLang, {   //translate from english to the selected language 
          not: '#footer',  //do not translate this item
          fromOriginal:true   //always translate from english (even after the page has been translated) 
           }); 
    }  
     
	$('#transMap')
      .find('area')
      .click(function(){
         var lang = $(this).attr('id');
         translateTo( lang );
         $.cookie('destLang', lang );
           this.blur();
  			return false;
     })
     
   
    var destLang = $.cookie('destLang'); //get previously translated language 
    if( destLang )  //if it was set then 
        translateTo( destLang ); 

 
  }); //end of Google Language API loaded 
   
}) //end of DOM ready



/* PRODUCT TABLE CODE */
$(function() {
	/* hide items to be shown only when hovered over or toggled*/
	$('.pPictureStrip,.pNotes,.pAdditionalInfo,.pTextOverRun').hide();  

	$('.pWrapper').hover(
	function() {
	$(this).find('.pStatWrapper > *, .pDescWrapper > .pAdditionalInfo').show();
	$(this).css("border-color","#d15d00")
	},
	function() {
	$(this).find('.pDescWrapper > .pAdditionalInfo, .pPictureStrip,.pNotes,.pTextOverRun').hide();
	$(this).find('.moreDesc').show();
	$(this).css("border-color","#e4e4e4 #FAFAFA")
	;
	});
	
	$('.moreDesc').click (function() {
		$(this).parent().parent().next().toggle();
		$(this).hide()
		return false; 
	});
	
      $('.morePhotos').click (function() {
                $(this).parents().find('.pPictureStrip').toggle();
                     return false; 
        }); 
	
	$('.moreInfo').click (function() {
		$(this).parents().find('.pNotes').toggle();
		return false; 
	});
	
});


/* LIGHTBOX CODE */
$(document).ready(function(){
			$(".lightBox").lightbox();
			
});


/* OVERLAY CODE */
$(document).ready(function(){
$('.moreDescs').click (function() {
			var myOverlay = (new documentOverlay())
        .css({
            background: 'black',
            opacity: 0.5,
            filter: 'alpha(opacity=50)'
        })
        .on('click',function(){
            myOverlay.remove();
        })
        .init();
        });
});

