// 
//  crown-sig.js
//  Crown Signature Club JavaScript
//  
//  Created by Victor Nguyen on 2009-09-07.
//  Copyright 2009 igloo digital. All rights reserved.
// 


var Crown = Crown || {};

// Signature-specific functionality
Crown.Sig = {
	
	init: function () {
		this.LandingFlash.init();
		this.Benefits.init();
	},
	
	FlashFallback: {
	    init: function() {
            $("#sig_landing_buttons a").each(function() {
                var height = $(this).css("height");
                $(this).css({"position":"relative"})
                       .append("<a />")
                       .find("a").css({"position":"absolute",
                                       "top":0,
                                       "left":0,
                                       "display":"none",
                                       "width":$(this).css("width"),
                                       "height":height,
                                       "background-image":$(this).css("background-image"),
                                       "background-position":"0 -"+height});
            });
            $("#sig_landing_buttons > a").hover(function() {
                $(this).find("a").fadeIn("fast");
            },function() {
                $(this).find("a").fadeOut("fast");
            });
	    }
	},
	
	LandingFlash: {
		
		SWF_PATH: '/flash/signature/signature-club.swf',
		EMBED_ID: 'sig_landing_flash',
		PROMO_BOOLEAN_ID: 'sig_landing_flash_wrapper',
		
		BUTTON_URLS: {
			BENEFITS: '/redirect/signature-benefits',
			EARN: '/redirect/signature-earn',
			JOIN: '/redirect/signature-join',
			PROMOS: '/redirect/signature-promotions',
			SIGN: '/redirect/signature-sign',
			JOINNOW: '/redirect/signature-joinnow',
			RULES: '/crown-signature-club-rules'

		},
		
		init: function () {

			var flashvars = {
				promotions: Crown.Sig.LandingFlash._areTherePromotions(),
				benefitsUrl: Crown.Sig.LandingFlash.BUTTON_URLS.BENEFITS,
				clubPointsUrl: Crown.Sig.LandingFlash.BUTTON_URLS.EARN,
				howToUrl: Crown.Sig.LandingFlash.BUTTON_URLS.JOIN,
				promotionsUrl: Crown.Sig.LandingFlash.BUTTON_URLS.PROMOS,
				signInUrl: Crown.Sig.LandingFlash.BUTTON_URLS.SIGN,
				joinUrl: Crown.Sig.LandingFlash.BUTTON_URLS.JOINNOW,
				rulesUrl: Crown.Sig.LandingFlash.BUTTON_URLS.RULES
			};

			var params = {
				allowScriptAccess: "always",
				wmode: 'opaque'
			};

			var attributes = {
				
			};
      
            swfobject.embedSWF(Crown.Sig.LandingFlash.SWF_PATH, Crown.Sig.LandingFlash.EMBED_ID, "958", "461", "9.0.0", '/flash/expressInstall.swf',  flashvars, params, attributes, Crown.Sig.FlashFallback.init);
		},
		
		_areTherePromotions: function () {
			if ($('#' + Crown.Sig.LandingFlash.PROMO_BOOLEAN_ID).attr('rel') == 'promos_true') {
				return 1;
			} else {
				return 0;
			}
		}
	},
	
	// Silly JS to set height of Black Tier <ul> to the same height as the Platinum Tier <ul>
	Benefits: {
		
		PLATINUM_ID: 'sig_tier_platinum',
		BLACK_ID: 'sig_tier_black',
		
		init: function () {
			Crown.Sig.Benefits.setBlackHeight();
		},

		setBlackHeight: function () {
			$('#' + Crown.Sig.Benefits.BLACK_ID).children('ul').height(Crown.Sig.Benefits._getSilverHeight());
		},
		
		_getSilverHeight: function () {
			return $('#' + Crown.Sig.Benefits.PLATINUM_ID).children('ul').height();
		}
		
	}
	
};


// on domready
$(document).ready(function(){
	Crown.Sig.init();
});
