// Generic All Page JS
count = 0;

function messages_fade_hide(){
	$("#alert_messages ul").fadeTo("slow", 0.01, function(){ //fade
		 $("#alert_messages ul li").slideUp("slow", function() { //slide up 
		 });
	 });
}

function navDropDowns(){
	$('a.drop_down').hover(function(){
		count = 0;
		$('.nav_dropdown').hide();		
		current_tab = $(this).parent().attr('id');
		$('#'+current_tab+'_dropdown').show();
	}, function() {
		count = 1;
		timeOut(current_tab);
		$('#'+current_tab+'_dropdown div').hover(function(){
			count = 2;
		}, function() {
			$('.nav_dropdown').hide();	
		});
	});
}

function timeOut(current_tab){
	setTimeout(function(){dropDownTimeout(current_tab)}, 1000);
}

function dropDownTimeout (current_tab){
	if (count == 1){
		$('#'+current_tab+'_dropdown').hide();		
	}else{
		// Chill out!	
	}
}

function searchBoxHint(){
	// search box hint text
    var $main_search_input = $('#main_search input.search_field');
	
	$main_search_input.focus(function() {
		if (jQuery.trim($(this).val()) == 'Search Store...') $(this).val('');
	});
	
	$main_search_input.blur(function() {
		if (jQuery.trim($(this).val()) == '') $(this).val('Search Store...');
	});
	
	$main_search_input.blur();
    
    $('#main_search').submit(function(evt){
        if ($main_search_input.val() == 'Search Store...') {
            evt.preventDefault();
            $main_search_input.focus();
            return false;
        }
        return true;
    });
}

$(document).ready(function(){
	
	if ($.browser.msie){
		if ( parseInt(jQuery.browser.version) < 7){ 
			$('<ul id="compatibility_alert"><li>We strongly advise you to upgrade to the latest Internet Explorer or any modern browser to enhance your viewing experience.<br/> If you\'re stuck at work on IE6 the site is functional. Rest assured we feel for you...</li></ul>').insertBefore('#alert_messages');
		}
	}
	
	// init the nav dropdowns
	navDropDowns();
	
	// search box hints and focus events
	searchBoxHint();
	
	//header login/register shadowbox hook
	Shadowbox.init({
		onOpen: function(){
		},
		onChange: function(){
		}
	});
	
	Shadowbox.setup(".login_hook", {
       player: 'iframe',
       width: 560,
       height:445
    });
	
	$("div.email_field input").click(function(){
		orig_val = "Your email here";
		if ($(this).val() == orig_val){
			$(this).val("");
		}
	})
	
	$("div.email_field input").blur(function(){
		if ($(this).val() == ""){
			$(this).val(orig_val);		
		}else{
			// Chill out!!
		}	
	})
	
	// community page
	$('a.prevPage').show();
	$('a.nextPage').show();
	
	if ($('.messages').html() != null){
		setTimeout(function(){messages_fade_hide()}, 4000);
	}
	
	// generic select
    $('.generic_select select, select.generic_select').each(function(i){
        var $this = $(this);
        // check it's not already converted
        if (!$this.data('ssOpts')) {
    		$this.sSelect({ddMaxHeight: '300px'});
        }
	});
	// generic select short
    $('.generic_select_short select, select.generic_select_short').each(function(i){
        var $this = $(this);
        // check it's not already converted
        if (!$this.data('ssOpts')) {
    		$this.sSelect({ddMaxHeight: '300px'});
        }
	});
	
})
