// common.js 
// - should contain javascript that is used frequently throughout the ASW platform


// PREVENT USER FROM SEARCHING KEYWORD 'Search' (case sensitive) 
jQuery(function() {

	jQuery("#gh-primary-search form").submit(function(){
	    if ( ((jQuery(this).children('input').val()) == "Search") || ((jQuery(this).children('input').val().trim()) == "") ) {
			jQuery(this).children('input').attr("value", "")
	        return false;
	   }
	});
	
	//combine two functions in mini
	
	jQuery("#asw-search-header form").submit(function(){
	    if ( (jQuery(this).children('input').val().trim()) == "") {
			jQuery(this).children('input').attr("value", "")
	        return false;
	   }
	});

 


// SEARCH INPUT BLUR AND FOCUS HANDLER

    //create an array of default values
    textInputs = jQuery('.search-input');
    var defaultValue = new Array(); 

    jQuery('.search-input').each(function(i) {
        defaultValue[i] = textInputs[i].value;
    });

    //bind blur and focus events to each input
    jQuery('.search-input').each(function(i) {
        jQuery(this).bind("focus", function(){
            if ( jQuery(this).attr("value") == defaultValue[i] ) {jQuery(this).attr("value", "")}; 
        });
        jQuery(this).bind("blur", function(){
            if ( jQuery(this).attr("value") == "" ) {jQuery(this).attr("value", defaultValue[i])}; 
        });
    });

// SWAP IN NEW JPG LOGO FOR IE6

	if (jQuery.browser.msie && jQuery.browser.version.substr(0, 1) < 7) {
		if ( jQuery('#asw-header img.logo-asw').length > 0 ) {
			jQuery('#asw-header img.logo-asw').attr('src','/images/asw_logo.jpg');
		}
		else if ( jQuery('#asw-header img.logo-abw').length > 0 ) {
			jQuery('#asw-header img.logo-abw').attr('src','/images/abw_logo.jpg');			
		}
	}

});


// Easy access to the GET url paramaters
function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}


// CHECK FOR LEADERBOARD AD, PAINT AD AND CLOCK ONCE WINDOW LOADED 

jQuery(window).load(function() {
// IF LEADERBOARD AD (EMBED OR IMG) EXISTS THEN SET BG-COLOR AND BORDER-COLOR
	if (jQuery('#banner-leaderboard').length > 0) { 

        
		if (jQuery("#banner-leaderboard object").length > 0) {
			jQuery("#banner-leaderboard object").each(function(){
				if (jQuery(this).width() > 100) {
					jQuery("#banner-leaderboard").css({
						'background-color': '#f3f3f3',
						'border-color': '#ccc',
						'padding': '7px 0'
					});
                    jQuery("#outer-wrp").addClass('has-leaderboard');
				}
			});
		}
		
        if (jQuery("#banner-leaderboard embed").length > 0) {
			jQuery("#banner-leaderboard embed").each(function(){
				if (jQuery(this).width() > 100) {
					jQuery("#banner-leaderboard").css({
						'background-color': '#f3f3f3',
						'border-color': '#ccc',
						'padding': '7px 0'
					});
                    jQuery("#outer-wrp").addClass('has-leaderboard');
				}
			});
		}

        if (jQuery("#banner-leaderboard img").length > 0) {
			jQuery("#banner-leaderboard img").each(function(){
				if (jQuery(this).width() > 100) {
					jQuery("#banner-leaderboard").css({
						'background-color': '#f3f3f3',
						'border-color': '#ccc',
						'padding': '7px 0'
					});
                    jQuery("#outer-wrp").addClass('has-leaderboard');
				}
			});
		}

        if (jQuery("#banner-leaderboard iframe").length > 0) {
			jQuery("#banner-leaderboard iframe").each(function(){
				if (jQuery(this).width() > 100) {
					jQuery("#banner-leaderboard").css({
						'background-color': '#f3f3f3',
						'border-color': '#ccc',
						'padding': '7px 0'
					});
                    jQuery("#outer-wrp").addClass('has-leaderboard');
				}
			});
		}
		   				


	}
	

// IF CLOCK EXISTS
	if  (jQuery('#gh-nav-clock object').length > 0 ) {
		jQuery('body').addClass('has-clock');
	}	
	
});

