 $(document).ready(function(){
	
	$('#navigation li').hover(
        function(){ $(this).find('.dd').show(); $(this).find('a:eq(0)').addClass('dd-active'); },
        function(){ $(this).find('.dd').hide(); $(this).find('a:eq(0)').removeClass('dd-active'); }
    );
    
    $('#sidebar').jScrollPane();
    
    
		
	$('.star2').rating({
		
		callback: function(value, link){
			path = window.location.pathname + '?' + window.location.search.substring(1);
			
			window.location = 'http://www.nashbrotherstrading.com/includes/modules/product/record_rating.php?rating=' + value + '&product=' + $(this).attr("title") + '&url=' + escape(path);
		}
	});

	$("a[href^=http]").each(  
    	function(){  
		   	if(this.href.indexOf(location.hostname) == -1 && this.href.indexOf('print.coupons.com') == -1 && $(this).attr('title') != 'allow-pass-thru') {   
	        	$(this).click(function(){ 
					window.location = '/pages/external-link?url=' + escape($(this).attr('href'));
					return false;
				});
       		}   
		}  
	)  

	// z-index layering fix for IE7
	var zIndexNumber = 10000;
	$('div').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 10;
	});

 	
    $('.blink').
        focus(function() {
            if(this.title==this.value) {
                this.value = '';
            }
        }).
        blur(function(){
            if(this.value=='') {
                this.value = this.title;
            }
        });
		
	$("a[rel^='lightBox']").lightBox();
	
	$('#sidebar').jScrollPane();
	$('#sidebar-test').jScrollPane();
	
	/** Custom Select **/
	$('.custom-select').each(function(){
		var options = $(this).find('option');
		
		var selected_value = options.eq(0).html();
		
		var options_html = '';
		options.each(function(){
			options_html += '<li>' + $(this).html() + '</li>';
			if($(this).attr('selected'))
				selected_value = $(this).html();
		});
		
		var w = (parseInt($(this).css('width')) + 4) + 'px';
		var html = '';
		html += '<div class="select" style="width:'+w+'">';
		html += '<div class="select-head"><div class="select-value">' + selected_value + '</div></div>';
		html += '<div class="select-dd"><ul class="select-ul">';
		html += options_html;
		
		html += '</ul></div></div>';
		
		$(this).wrap('<div class="custom-select-holder">');
		$(this).before( html );
		
	});
	$('.select-value').click(function(e){
		var parent = $(this).parent().parent();
		var select_dd = parent.find('.select-dd');
		
		
		
		if( select_dd.css('display') == 'none') {
			$('.custom-select-holder').css({ 'z-index': 10 });
			$('.select-dd').hide();
			
			select_dd.show();
			parent.parent().css({ 'z-index': 100 });	
		}else {
			select_dd.hide();
			
		}
		
		
		$('body').click(function(){ 
			$('.custom-select-holder').css({ 'z-index': 10 });
			$('.select-dd').hide();
		});
		
		return false;
	});
	
	$('.select-dd').each(function(){
		var i=0;
		$(this).find('li').each(function(){
			this._index = i;
			i++;
		});
	})
	
	$('.select-dd li').click(function(){
		var parent = $(this).parent().parent().parent();
		var value = $(this).html();
		var index = this._index;
		var holder = parent.parent();
		
		parent.find('.select-value').html(value);
		parent.find('.select-dd').hide();
		
		holder.find('option').attr({ 'selected' : false });
		holder.find('option:eq('+index+')').attr({ 'selected' : true });
		
		return false;
	});	

});
