/*
	Site:		Wonderbra: Ultimate Strapless
	File:		/assets/scripts/global.js
	Version:	2009-07-20
----------------------------------------------- */


/*	Global Configuration
----------------------------------------------- */

var spinner = '<div class="loading"><img src="/public/img/spinner.gif" alt="loading" /></div>';

$(function() {
	Setup.init();
	$(".flip_book").colorbox({width:"95%", height:"95%", iframe:true});
});

var Setup = {	
	Body: null,
	init: function() {
		var cc = this;
		cc.Body = $(document.body);
		cc.Body.addClass('domReady');
		/* Template: Home */
		if(cc.Body.hasClass('home')) {
			TemplateHome.init();
		}	
		// external links
		$("a[rel='external']").each(function() {
			var link = $(this);
			link .click(function() {
				return !window.open(link.attr('href'));
			});
		});
		Cufon.replace('h1');
		equalHeight($('#Footer div.item'));
		imageBorders($('img.border'));
		
		$('table').each(function(){
			var cols = $(this).find('th');
			var width = 100/cols.length;
			cols.width(width+'%');
		});
	}

};

/*	Template: Home
----------------------------------------------- */
var TemplateHome = {
	init: function() {
		var cc = this;
		cc.events();
		cc.render();
	},
	events: function() {
		var cc = this;

	},
	render: function() {
		var cc = this;
		
		/* Promotions */
		equalHeight($('#Content div.promotions div.item'));
	}
};

/*	Functions
----------------------------------------------- */
function equalHeight(group) {
	tallest = 0;
    group.each(function() {
        thisHeight = $(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}

function imageBorders(group) {
	group.each(function() {
		var image = $(this);
		var parent = image.parent('a');
		if(parent.length>0) {
			parent.wrap("<div class=\"image border\"><div class=\"wpr\"></div></div>");
		} else {
			image.wrap("<div class=\"image border\"><div class=\"wpr\"></div></div>");
		}
	});	
}


