
/* **** Add Javascript Enabled Styles *********************** */
(function() {
	var head = document.getElementsByTagName("head")[0];
	if (head) {
		var scriptStyles = document.createElement("link");
		scriptStyles.rel = "stylesheet";
		scriptStyles.type = "text/css";
		scriptStyles.href = "themes/awesomeshirt/css/awesomeshirt-js.css";
		scriptStyles.media = "screen,print";
		head.appendChild(scriptStyles);
	}
} ());

/* **** JQuery Functions - jquery-1.3.2.min.js ************** */

$(document).ready( function()
{
	SetExternalLinks();
	TabsInit();
	
	if($("body.redirect .redirect-message a.redirect-link").length > 0) {
		PageRedirectInit();
	}
	
	if($(".image-list").length > 0) {
		ColorBoxInit();
	}
	
	if($(".product-list .details").length > 0) {
		DetailShowHideInit();
	}
	
});

/* *** Set External Link *************************** */

function SetExternalLinks(){
	/*
	Purpose: checks all <a>'s in the doc, if it has a rel attribute of 'external', sets to open in new window
	usage: 
	*/
	
	$('a[rel=external],a[rel="nofollow external"],.external a').click(function() {
		window.open(this.href);
		return false;
	});
	
	// $('a[rel="external"]').click(function(){ window.open(this.href); return false; });
}

/* *** Set ColorBox ******************************** */

function ColorBoxInit() {
    $('.image-list li a').colorbox({transition:"elastic"});
}

/* *** Set Tab Groups ****************************** */

function TabsInit() {
	
	if($(".tab-group").length > 0) {
		
		$(".tab-group").each(function() {
			
			if($(this).children(".tab-holder").length > 0) {
				
				$(this).children(".tab-holder").hide();
				$(this).children(".tab-holder:first").show();
				
				$(this).prepend('<ul class="tabs"></ul>');
				
				$(this).children(".tab-holder").each(function(){
					linkID = $(this).attr("id");
					linkTitle = $(this).children("h2").text();
					linkHtml = '<li><a rel="'+linkID+'" href="#'+linkID+'">'+linkTitle+'</li>'
					
					$(this).children("h2").remove();
					
					$(this).siblings("ul.tabs").append(linkHtml);
					
				});
				
				$(this).children("ul.tabs li:first").addClass("selected");
			
			}
			
		});
		
		$(".tab-group ul.tabs a").click(function() {
			
			targetID = $(this).attr("rel")
			
			$(this).parent().parent().parent().children(".tab-holder").hide();
			$(this).parent().siblings(".selected").removeClass("selected")
			$(this).parent().addClass("selected");
			
			$(this).parent().parent().siblings("#"+targetID).show();
			
			return false;
		})
	}
}

/* *** Product List Details Show/Hide ************** */

function DetailShowHideInit() {
	$(".product-list li a.image").mouseover(function() {
		$(this).siblings(".details").css("opacity",0).show().animate({ 
			opacity: 0.9,
			display: "block"
		}, 100);
	});
	
	$(".product-list li .details").mouseleave(function() {
		$(this).fadeOut(100);
	});
}
	
/* *** Redirect Page ******************************* */

function PageRedirectInit() {
	setTimeout('PageRedirectUrl()',5000);
	
}

function PageRedirectUrl() {
	RedirectUrl = $("body.redirect .redirect-message a.redirect-link").attr("href");
	window.location = RedirectUrl;
}