// CONTENTS ====================================================================
/*
- DEFAULT
*/

// DEFAULT --------------------------------------------------------------

var FrontendMain = {

	InitDefaultMain : function () {
		// NAV CENTERING: gets width of the main lav list items and centers the nav
		var totalWidth = 0;
		var initMargin = 0;
		$("#main-nav li").each(function(){
			totalWidth += ( $(this).outerWidth() + parseInt( $(this).css("margin-left") ) );
			initMargin = $(this).css("margin-left");
		})
		if (!jQuery.browser.msie || (jQuery.browser.msie && parseInt(jQuery.browser.version) > 6) ) {
  			$("#main-nav li:first").css("margin-left", ((960 - totalWidth) / 2) + (parseInt(initMargin)/2));
		}
		
		// SUBNAV: clears every 6th item so if any run to 2 lines it doesnt break the grid
		$("#secondary-nav li:nth-child(5n+1)").addClass("clear");
	},
	
	InitColorBoxVideo : function() {
	
		$("div.video a").each(function() {

			$(this).colorbox({
				iframe:true, 
				width:660, 
				height:405
			});
		});
		
	},
	
	/* Adds the 'last' class to the tables created in the Detail page WYSIWYG editor */
	InitTable : function() {
	
		$("table[class != 'features'] tbody tr td:last-child").each( 
			function() {
				$(this).addClass('last');
			});
			
	},
	
	InitColorBoxListingItem : function() {
	
		$(".listings li a.img").each(function() {
			$(this).colorbox();
		});	
		
	},

	InitCommentQuote : function() {
	
		$("div.comment:has(cite)").each(function() {
			var $quoteClass;
			if($(this).hasClass('large-comment')) {
				$quoteClass = 'large-quote';
			} else {
				$quoteClass = 'quote';
			}
			$(this).find('p').after('<div class="' + $quoteClass + '">&nbsp;</div>')
		});
		
	},
	
	SetExternalLinks : function() {
	
		/*
		Purpose: checks all <a>'s in the doc, if it has a rel attribute of 'external', sets to open in new window
		usage: <a href="http://www.google.com" rel="external">Google</a>
		*/
		
		$('a[rel=external]').click(function(){ window.open(this.href); return false; });
	},
	
	ColorFormAsterisk : function() {
	
		var split = $('.required-note').text().split("*");
		$('.required-note').replaceWith('<p class="required-note">' + split[0] + '<span>*</span>' + split[1] + '</p>');
	
	},
	
	SetCurrencyLinks : function() {
		$('.body-text a').each( function(){
			$this = $(this)
			if($this.text().indexOf("$") != -1){	
				$this.addClass("currency-converter-link");
			}
		});
	}
	
	
	
}