/*
 * Droppy 0.1.2
 * (c) 2008 Jason Frame (jason@onehackoranother.com)
 */
$.fn.droppy = function(options) {
    
  options = $.extend({speed: 250}, options || {});
  
  this.each(function() {
    
    var root = this, zIndex = 30000;
    
    function getSubnav(ele) {
      if (ele.nodeName.toLowerCase() == 'li') {
        var subnav = $('> div, > ul', ele);
        return subnav.length ? subnav[0] : null;
      } else {
        return ele;
      }
    }
    
    /*function getActuator(ele) {
		alert(ele.nodeName);
      if (ele.nodeName.toLowerCase() == 'div') {
        return $(ele).parents('li')[0];
      } else {
        return ele;
      }
    }*/
    
    function hide() {
      var subnav = getSubnav(this);
      if (!subnav) return;
	  var thethis = this
	  
      $.data(subnav, 'cancelHide', false);
      setTimeout(function() {
        if (!$.data(subnav, 'cancelHide')) {
			
          $(thethis).removeClass('hover'); $('> a', thethis).removeClass('hover');
		  
		  $(subnav).slideUp(options.speed);
		  
		  
        }
      }, 500);
    }
  
    function show() {
      var subnav = getSubnav(this);
      if (!subnav) return;
      $.data(subnav, 'cancelHide', true);
      $(subnav).css({zIndex: zIndex++}).slideDown(options.speed);
	 
	  $(subnav).parent().css({zIndex: zIndex});//ie adds a bloody margin!?!?!
	  
	  $(this).addClass('hover'); $('> a', this).addClass('hover');
      
	  /*alert(this.nodeName);
	  if (this.nodeName.toLowerCase() == 'li') {
        var li = getActuator(this);
        $(li).addClass('hover');
        $('> a', li).addClass('hover');
      }*/
	  
	  
    }
    
    $('li', this).hover(show, hide);
    //$('li', this).hover(
      //function() { $(this).addClass('hover'); $('> a', this).addClass('hover');}
    //);
    
  });
  
};


$(function(){

	$('.secondnav, .headright ul, .nav').droppy();
	
	$('.fader').hover(
		function(){
			$(this).stop().fadeTo(400,0.7);
		},
		function(){
			$(this).stop().fadeTo(400,1);
	});
	
	$('.backtotop').bind('click',function(){$('html, body').animate({scrollTop: 0}, 2000); return false});
		
	
	//clear default
	$('.textfield, .clearthis').bind('focus',function(){
		if (this.defaultValue==this.value) this.value = "";
	}).bind('blur',function(){
		if (this.value=="") this.value = this.defaultValue;
	});
	
	
	
	$('.descripreadmore').click(function(){
		if(!$(this).hasClass('descripcollapse')){
			$('.variantscol').hide();
			$('.descripcol').css({width:'579px'});
			$('.descrisynop').hide();
			$('.hideme').show();//binds hide function to click box
			$('.descripreadmore').removeClass('greylink').addClass('descripcollapse bluelink').html('Close');
			
		}else{
			$('.variantscol').show();
			$('.descripcol').css({width:'264px'});
			$('.descrisynop').show();
			$('.hideme').hide();
			$('.descripreadmore').addClass('greylink').removeClass('descripcollapse bluelink').html('Read More...');
		};
		
		
		
		return false;
	});
	
	
	//external links
	exttarget();
	
	
	//copy billing address in account page
	$('.usebill').click(function(){
		
		$('#account-ship_addr1').val($('#account-bill_addr1').val());
		$('#account-ship_addr2').val($('#account-bill_addr2').val());
		
		$('#account-ship_city').val($('#account-bill_city').val());
		$('#account-ship_county').val($('#account-bill_county').val());
		
		$('#account-ship_postcode').val($('#account-bill_postcode').val());
		
		var selectb = $('#account-bill_country option:selected').val();
		$('#account-ship_country option').each(function(){
		
			if($(this).val()==selectb){
				$(this).attr('selected', 'selected');	
			}
			
		});
		
		return false;
	});
	
	
	
	
});

