/**
 * Flash variables for universal use
 */
var flashVersion = '9.0.18';
var flashExpressInstallUrl = '/_ui/libs/swfobject/expressInstall.swf';
var flashVars = {};
var flashParams = {
    wmode: 'transparent',
    quality: 'high'
};


/**
 * Home page
 */
function scottspro_front() {
    // Flash
    if(swfobject.hasFlashPlayerVersion(flashVersion)) {
        $('#wrap, #flash-hero').addClass('flash');
        swfobject.embedSWF(
            '/_ui/skin/swf/home_hero.swf', // swf
            'flash-replacement', // id
            '876', // width
            '334', // height
            flashVersion, flashExpressInstallUrl, // don't change
            flashVars,
            flashParams
        );
    }
}


/**
 * Regions
 */
function prepRegionPage() {
	// add classes to table columns
	$('.subRegion table tr td:first-child, .subRegion table tr th:first-child').addClass('crops');
	$('.subRegion table tr td:last-child, .subRegion table tr th:last-child').addClass('fertilizer');
	
	$('.subRegion table tr:even').addClass('even');
	$('.subRegion table tr:odd').addClass('odd');
	
	// add class to list-item last child
	$('ul.regionSubNav li:last-child').addClass('last-child');
	$('ul.regionSubNav li:first-child').addClass('first-child');
	
	$('#frmSelectRegion select').change(function(){
		$(this).parents('form').submit();
	});
}


/**
 * onLoad
 */
$(function() {
    // Testimonial
    swfobject.embedSWF(
        '/_ui/skin/swf/testimonials.swf',
        'flash-testimonial',
        '186',
        '500',
        flashVersion, flashExpressInstallUrl,
        flashVars,
        flashParams
    );
    
    // Search
    $('#search input.form-submit').hover(function() {
        $(this).addClass('hover');
    }, function() {
        $(this).removeClass('hover');
    });
    
    // Scotts Exchange Form
    $('#node-46').each(function() {
        $('#edit-submitted-product-types-Other').change(function() {
            if($(this).attr('checked')) {
                $('#webform-component-product_types_other').show();
            }
            else {
                $('#webform-component-product_types_other').hide();
            }
        });
        $('#edit-submitted-newsletter-Yes').change(function() {
            if($(this).attr('checked')) {
                $('#webform-component-email').show();
            }
            else {
                $('#webform-component-email').hide();
            }
        });
    });
    
    // Front
    if($('body.front-page').length) {
        scottspro_front();
    }
    
    if($('.node-region').length) {
    	prepRegionPage();
    }
    
    prepRegionPage();
    
	// jnice - but not for ie6
    if (navigator.appVersion.toLowerCase().indexOf('msie 6') == -1) {
    	$('#resourcesForm, #frmSelectRegion').jNice();
    }
    
    // Flash piece for agriblen
    var agriBlen = $('#agriblen');
    if ($('body').hasClass('es')) {
    	var agriBlenSwf = '/_ui/skin/swf/agriblen_spanish.swf';
    } else {
    	var agriBlenSwf = '/_ui/skin/swf/agriblen.swf';
    }
    if (agriBlen.length) {
        swfobject.embedSWF(
            agriBlenSwf,
            'agriblen',
            '150',
            '314',
            flashVersion, flashExpressInstallUrl,
            flashVars,
            flashParams
        );
    }
    
    // External links
    $("a[href^=http]").not("[href*=scottspro]").addClass("extLink").attr("target","_blank");
});
