$(document).ready(init_page);

// init_sifr();

function init_page(){
  $('#kwd').focus(function(){
    
    if($(this).val()=='Search Site')$(this).val('');
    
  });

  $("#search_submit").hover(function(){$(this).css('background-color','#9cbd55')},function(){$(this).css('background-color','#6e8d25')});
  $("#product_search_submit").hover(function(){$(this).css('background-color','#9cbd55')},function(){$(this).css('background-color','#6e8d25')});
 /* if($('#top_banner img').get(0)!=undefined){

    
    $('#top_banner img').get(0).onload = function(){
      $('#top_banner').height($('#top_banner img').height() );
      $('#top_banner').width($('#top_banner img').width() );
      
 
    }
  }*/
	
	// Marc 06/24/2011 - Added no_repeat to halt the sliding after the final slide
	// set to false or remove to enable sliding to loop back to first slide
	$("#banner").slider({
		loading_image:false,
		autostart:true,
		speed:1400,
		delay:4500,
		transition:'fade',
		nav_buttons_img:false,
		no_repeat:true
	});
  
    
  $('#site_search').submit(function(){
    $('#kwd').focus();
  });
  $('.lightbox').lightBox();
  init_select_location();

}

function init_gallery_thumbnails(){
  
  // Home page gallery
  $('.gallery[screen]').each(function(){
    
    var screen = $(this).attr('screen');
    $(screen).css({
        'height':$(screen).height() + 'px',
        'width':$(screen).width() + 'px',
        'position':'relative'});
    $(screen  + ' img').remove();
		// Initialize Galleriffic
		$(this).galleriffic({
		  childrenSelector:'.gallery_item .frame',
			imageContainerSel:screen,
			selectedClass: 'current-page-item',
			syncTransitions:true,
			autoStart:true,
			delay:4000,
			clickToLink:false
		});

    
  })

}


function is_valid_email(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email) == false) {
      return false;
   }
   return true;
}


function init_select_location(){
  var location_selector = $('#select_location .selector');
  var location_options = $('#select_location #location_options');
  
  function position_options(){
    var offset = location_selector.offset();
    location_options.css({'position':'absolute','top':(offset.top + 20)+'px','left': offset.left + 'px'});
  }
  
  $(window).resize(position_options);
  position_options();
  
  location_options.css({width:location_selector.width()});
  $('body').append(location_options);
  
  $(location_selector).click(function(){
    if(location_options.css('display')=='none'){
      location_options.show();
    }else{
      location_options.hide();
    }
    return false;

  }).hover(function() {
		location_options.show();
	}, function() {	
		location_options.hide();
	});
	
	location_options.hover(function() {
		location_options.show();
	}, function() {	
		location_options.hide();
	});
  
  location_options.find('li a').click(function(){
    document.cookie = 'location=' + $(this).attr('location') + '; expires=Thu, 2 Aug 2050 20:47:11 UTC; path=/';
    
    
    location_options.hide();  
  });
  location_options.hide();
  
}


