/*
	Site:		Shock Absorber: Run Ball Racket
	File:		/assets/scripts/global.js
	Author:		Andrew Disley, Simplified http://simplified.co.uk/
	Version:	2009-12-01
----------------------------------------------- */

/*	Global Configuration
----------------------------------------------- */
var $j = jQuery;
var isIE = false;
var isIE6 = false;
var isSafari = false;

jQuery.fn.jWait = function(duration) {
	jQuery(this).animate({ dummy: 1 }, duration);
	return this;
};

var getStyleProperty = (function() {
	var prefixes = ['Moz', 'Webkit', 'Khtml', 'O', 'Ms'];
	function getStyleProperty(propName, element) {
		element = element || document.documentElement;
		var style = element.style,
		prefixed;
		if (typeof style[propName] == 'string') {
			return propName;
		}
		propName = propName.charAt(0).toUpperCase() + propName.slice(1);
		for (var i=0, l=prefixes.length; i<l; i++) {
			prefixed = prefixes[i] + propName;
			if (typeof style[prefixed] == 'string') {
				return prefixed;
			}
		}
		return false;
	}
	return getStyleProperty;
})();

/*	Global Literal Object: Site-wide functions
----------------------------------------------- */
var SGlobal = {

	/* Configuration, Flags and Messages */
	cWindowWidth: null,
	cWindowWidthReq: null,
	
	/* jQuery Object References  */
	jEOBody: null,
	jEONavigationGlobal: null,

	/* Utility: Browser Tests / Specific Fixes/Hooks */
	utilBrowserTests : function() {

		if ($j.browser.msie) { isIE = true; }
		/* Detect if User Agent is IE6 using object detection, apply fix for background flicker bug */
		if (typeof document.body.style.maxHeight == 'undefined') { isIE6 = true; try { document.execCommand('BackgroundImageCache', false, true); } catch(e) { } }

		/* Detect if User Agent is Safari, add class '.safari' to div#Container */
		if ($j.browser.safari) { isSafari = true; $j('div#Container').addClass('safari'); }

	},

	styleGlobalNav : function(){

		var cc = this;
		
		cc.jEONavigationGlobal.css('left', '-35px');

		/* If window width >= cWindowWidthReqhide show jEONavigationGlobal else only show 12px and enable hover effects */
		if (cc.cWindowWidth >= cc.cWindowWidthReq) {
			cc.jEONavigationGlobal.jWait(1000).css('left', '-35px').animate({ left: '+=35px' });
		} else {
			cc.jEONavigationGlobal.jWait(1000).css('left', '-35px').animate({ left: '+=12px' });
			cc.jEONavigationGlobal.hover(function() {
				cc.jEONavigationGlobal.animate({ left: '+=23px' });
			}, function() {
				cc.jEONavigationGlobal.animate({ left: '-=23px'});
			});
		}

	},

	init : function() {

		var cc = this;

		cc.cWindowWidth = $j(window).width();
		cc.cWindowWidthReq = '1000';

		cc.jEOBody = $j('body').addClass('jQ');
		cc.jEONavigationGlobal = $j('div#NavigationGlobal');

		cc.utilBrowserTests();
		cc.styleGlobalNav();

	}

};

/*	Components Object
----------------------------------------------- */
var SComponents = {

    /* Configuration */
    cModalExpose: null,

    /* jQuery Object References */
    jEOHomeCTA: null,
    jEOProduct: null,
    jEOProductCTA: null,
    jEOFeatures: null,
    jEOFeaturesCTA: null,
    jEOFocusOnTabs: null,
    jEOFocusOnTabsNav: null,
    jEOBuyButton: null,

    sCHomeCTA: function() {

        var cc = this;

        $j('.c-b', cc.jEOHomeCTA).flashembed({
            version: [10, 0],
            bgcolor: '#000000',
            expressInstall: 'assets/swf/expressinstall.swf',
            src: 'assets/swf/preloader-2.swf',
            menu: false,
            wmode: 'opaque',
            quality: 'high'
        }, {
            swf: 'assets/swf/c-home-cta-2.swf',
            runFind: 'run-sportsbra.html',
            runBuy: '#',
            runFigleaves: escape('http://www.figleaves.com/uk/product.asp?product=Shock-Absorber-Run-B5044-Sports-Bra&product_id=BB-B5044&size=&colour=Black'),
	        runBoobydoo: escape('http://www.boobydoo.co.uk/sportsbra/productdetail.cfm?productid=93&sourceid=9'),
	        runLessbounce: 'http://www.lessbounce.com/acatalog/Online_Catalogue_Shock_Absorber_Sports_Bras__4.html',
	        runOther: 'http://www.shockabsorber.co.uk/home/wheretobuy/index.htm',
            ballFind: 'ball-sportsbra.html',
            ballBuy: '#',
            ballFigleaves: escape('http://www.figleaves.com/uk/product.asp?product=Shock-Absorber-Ball-B5046-Sports-Bra&product_id=BB-B5046&size=&colour=White'),
            ballBoobydoo: escape('http://www.boobydoo.co.uk/sportsbra/productdetail.cfm?bra=b5046_ball_sports_bra&productid=94'),
            ballLessbounce: 'http://www.lessbounce.com/acatalog/Online_Catalogue_Shock_Absorber_Sports_Bras__4.html',
	        ballOther: 'http://www.shockabsorber.co.uk/home/wheretobuy/index.htm',
            racketFind: 'racket-sportsbra.html',
            racketBuy: '#',
            racketFigleaves: escape('http://www.figleaves.com/uk/product.asp?product=Shock-Absorber-Racket-B5047-Sports-Bra&product_id=BB-B5047&size=&colour=White'),
            racketBoobydoo: escape('http://www.boobydoo.co.uk/sportsbra/productdetail.cfm?bra=b5047_racket_sports_bra&productid=95'),
            racketLessbounce: 'http://www.lessbounce.com/acatalog/Online_Catalogue_Shock_Absorber_Sports_Bras__4.html',
	        racketOther: 'http://www.shockabsorber.co.uk/home/wheretobuy/index.htm'
        });

    },

    sCProductModal: function() {

        var cc = this;

        /* Using CFT test if borderRadius is supported */
        if (typeof getStyleProperty('borderRadius') == 'string') {
            /* If borderRadius is supported apply to Modal */
            cc.jEOFeatures.css(getStyleProperty('borderRadius'), '10px');
            cc.jEOFeaturesItems.css(getStyleProperty('borderRadius'), '10px');
        }

        cc.jEOFeaturesCTA.overlay({
            expose: cc.cModalExpose,
            left: 40,
            target: cc.jEOFeatures,
            top: 10
        });

    },

    sCProductHover: function() {

        var cc = this;

        cc.jEOProductCTA.hover(function() {
            cc.jEOProduct.css('display', 'none');
        }, function() {
            cc.jEOProduct.removeAttr('style');
        });

    },

    sCFocusOnTabs: function() {

        var cc = this;

        cc.jEOFocusOnTabsNav.tabs(cc.jEOFocusOnTabs, {
            current: 'active',
            effect: 'fade',
            fadeOutSpeed: "slow"
            //			,rotate: true
        });

    },

    sCBuyButton: function() {

        var cc = this;

        cc.jEOBuyButton.hover(function() {
            cc.jEOBuyButton.find('a:first').addClass('hover');
            cc.jEOBuyButton.parent().find('ul').show();
        }, function() {
            cc.jEOBuyButton.find('a:first').removeClass('hover');
            cc.jEOBuyButton.parent().find('ul').hide();
        });
    },

    init: function() {

        var cc = this;

        /* Configuration */
        if (isIE) {
            cc.cModalExpose = null;
        } else {
            cc.cModalExpose = {
                color: '#000000',
                loadSpeed: 200,
                maskId: 'ModalExpose',
                opacity: 0.8
            };
        }

        /* jQuery Object References */
        cc.jEOHomeCTA = $j('#Content div.c-home-cta');
        cc.jEOProduct = $j('.c-product h3 img');
        cc.jEOProductCTA = $j('.c-content .c-b strong, .c-product .c-b h4');
        cc.jEOFeatures = $j('#Features');
        cc.jEOFeaturesItems = $j('li span', cc.jEOFeatures);
        cc.jEOFeaturesCTA = $j('#Content div.c-product h3, #Content div.c-product li.features a');
        cc.jEOFocusOnTabs = $j('body.focuson #Content .c-item');
        cc.jEOFocusOnTabsNav = $j('body.focuson #TOC');
        cc.jEOBuyButton = $j('div.c-product ul li.buy');

        if (cc.jEOHomeCTA.length) {
            cc.sCHomeCTA();
        }

        if (cc.jEOFeatures.length && cc.jEOFeaturesCTA.length) {
            cc.sCProductModal();
        }

        if (cc.jEOProduct.length && cc.jEOProductCTA.length) {
            cc.sCProductHover();
        }

        if (cc.jEOBuyButton.length) {
            cc.sCBuyButton();
        }


        /*
        if (cc.jEOFocusOnTabs.length) {
        cc.sCFocusOnTabs();
        }
        */

    }

};

/*	DOM Ready events
----------------------------------------------- */
$j(function() {

	SGlobal.init();

	SComponents.init();

});

