var wT = 255;
var bT = 224;
var wE = 245;
var bE = 234;
var wS = 204;
var bS = 214;
var n1 = 273;
var n2 = 283;

var intel = {
	urlVars: [],
	viewingBack: false,
	init: function() {
		
		// acquire us some url variables
		var hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); // grab everything after '?' and split the remaining string by '&'
		for(var i = 0; i < hashes.length; i++) { // rolling through strings that looks like lValue=rValue
			hash = hashes[i].split('='); // split the string by '='
			intel.urlVars.push(hash[0].toLowerCase()); // jam on another piece here
			intel.urlVars[hash[0].toLowerCase()] = hash[1]; // fill said piece with meaningful stuff
		}
		
		// highlight the current image in the slider bar
		switch (intel.urlVars['productid']) {
			case '255':
				intel.lightSliderId('#wT');
				break;
			case '224':
				intel.lightSliderId('#bT');
				break;
			case '245':
				intel.lightSliderId('#wE');
				break;
			case '234':
				intel.lightSliderId('#bE');
				break;
			case '204':
				intel.lightSliderId('#wS');
				break;
			case '214':
				intel.lightSliderId('#bS');
				break;
			case '273':
				intel.lightSliderId('#n1');
				break;
			case '283':
				intel.lightSliderId('#n2');
				break;
		}
		
		$('#productImage').html('<img src="images/shirts/'+ intel.urlVars['productid'] +'.jpg" rel="orig" />');
		
		// reorder sizes
		$('#sizeSelection select').html('<option value="Select Size">Select Size</option><option value="SM">SM</option><option value="MD">MD</option><option value="LG">LG</option><option value="XL">XL</option><option value="2XL">2XL</option><option value="3XL">3XL</option><option value="4XL">4XL</option><option value="5XL">5XL</option><option value="6XL">6XL</option>');
		
	},
	lightSliderId: function(id) {
		thisId = $(id);
		thisId.attr('src', thisId.attr('src').replace('d.jpg', '.jpg'));
		thisId.attr('rel', 'active');
	},
	toggleBack: function() {
		image = $('#productImage img');
		if (intel.urlVars['productid'] == '255' || intel.urlVars['productid'] == '245' || intel.urlVars['productid'] == '204') { // white
			if (image.attr('rel') == 'orig') {
				image.removeAttr('rel');
				image.attr('src', image.attr('src').replace(intel.urlVars['productid'], 'wB'));
			} else {
				image.attr('rel', 'orig');
				image.attr('src', image.attr('src').replace('wB', intel.urlVars['productid']));
			}
		} else if (intel.urlVars['productid'] == '224' || intel.urlVars['productid'] == '234' || intel.urlVars['productid'] == '214') { // blue
			if (image.attr('rel') == 'orig') {
				image.removeAttr('rel');
				image.attr('src', image.attr('src').replace(intel.urlVars['productid'], 'bB'));
			} else {
				image.attr('rel', 'orig');
				image.attr('src', image.attr('src').replace('bB', intel.urlVars['productid']));
			}
		} else if (intel.urlVars['productid'] == '273') { // n1
			if (image.attr('rel') == 'orig') {
				image.removeAttr('rel');
				image.attr('src', image.attr('src').replace(intel.urlVars['productid'], 'n1B'));
			} else {
				image.attr('rel', 'orig');
				image.attr('src', image.attr('src').replace('n1B', intel.urlVars['productid']));
			}
		} else if (intel.urlVars['productid'] == '283') { // n2
			if (image.attr('rel') == 'orig') {
				image.removeAttr('rel');
				image.attr('src', image.attr('src').replace(intel.urlVars['productid'], 'n2B'));
			} else {
				image.attr('rel', 'orig');
				image.attr('src', image.attr('src').replace('n2B', intel.urlVars['productid']));
			}
		}
	}
}

function checkErrors() {
	if ($('#ctl00_valSummary').html() != '') {
		$('#ctl00_valSummary').html("<div id=\"errorMessages\" class=\"modal error\"><div class=\"header\">There are problems with your submission</div><div class=\"content\">"+$('#ctl00_valSummary').html()+"</div></div>");
	}
}

$(document).ready(function() {
	intel.init();
	$('#slider img[rel!=active]').hover(function(){$(this).attr('src',$(this).attr('src').replace('d.jpg','.jpg'));},function(){$(this).attr('src',$(this).attr('src').replace('.jpg','d.jpg'));});
	$('#ctl00_valSummary').html('');
	$('#ctl00_tcContent_btnContinue').mouseup(function(){
		setTimeout('checkErrors()',10);
	});
});