/* schemas */

/*  these background images are defined on the page 
var schemes = new Array();
schemes[1] = 'http://www.atlanticrecords.com/style/common/bgschemes/paolo_1.jpg';
schemes[2] = 'http://www.atlanticrecords.com/style/common/bgschemes/paolo_2.jpg';
*/

var SchemaSelector = {
	// Properties	
	skins: new Array(
		/*atlantic*/	{'highlights':'#ec1c24','lowlights':'#231f20','headertext':'#ffffff','background':'#2f2e2a','subhd':'#371e1d','subhdtext':'#ec1c24','inputs':'#ec1c24','inputtext':'#ffffff','date':'#999999','links':'#ec1c24','textColor':'#ffffff'},
		/*forest*/		{'highlights':'#438459','lowlights':'#281b0b','headertext':'#ffffff','background':'#223728','subhd':'#6a5537','subhdtext':'#d5bd9a','inputs':'#a0845c','inputtext':'#ffffff','date':'#999999','links':'#438459','textColor':'#ffffff'},
		/*aquatic*/		{'highlights':'#187084','lowlights':'#231f20','headertext':'#ffffff','background':'#052d34','subhd':'#331704','subhdtext':'#187084','inputs':'#231f20','inputtext':'#ffffff','date':'#999999','links':'#187084','textColor':'#ffffff'},
		/*prep*/		{'highlights':'#ee461f','lowlights':'#260900','headertext':'#ffffff','background':'#3f3325','subhd':'#6a5537','subhdtext':'#fcf487','inputs':'#ee461f','inputtext':'#ffffff','date':'#999999','links':'#ee461f','textColor':'#ffffff'},
		/*ice*/			{'highlights':'#667d88','lowlights':'#667d88','headertext':'#c8f2fe','background':'#28353b','subhd':'#B7D8E7','subhdtext':'#4f9cc1','inputs':'#b8d9e8','inputtext':'#3fa5d1','date':'#999999','links':'#B7D8E7','textColor':'#ffffff'},
		/*skaterchic*/	{'highlights':'#e41496','lowlights':'#231f21','headertext':'#ffffff','background':'#666666','subhd':'#333333','subhdtext':'#e71395','inputs':'#610b1f','inputtext':'#ffffff','date':'#999999','links':'#e41496','textColor':'#ffffff'},
		/* 7-lupefiasco	{'highlights':'#9c78c7','lowlights':'#2a2145','headertext':'#ffffff','background':'#000000','subhd':'#111111','subhdtext':'#9c78c7','inputs':'#9c78c7','inputtext':'#ffffff','date':'#999999','links':'#ffffff','textColor':'#ffffff'},*/
						{'highlights':'#4c8c02','lowlights':'#231f20','headertext':'#ffffff','background':'#000000','subhd':'#4c8c02','subhdtext':'#ffffff','inputs':'#4c8c02','inputtext':'#ffffff','date':'#ffffff','links':'#4c8c02','textColor':'#ffffff'},
		/* 8-lauraizibor*/	{'highlights':'#b58300','lowlights':'#352b10','headertext':'#ffffff','background':'#000000','subhd':'#825e00','subhdtext':'#c19c3a','inputs':'#553f03','inputtext':'#ffffff','date':'#999999','links':'#b58300','textColor':'#ffffff'},
		/* 9-serenaryder*/	{'highlights':'#877f5b','lowlights':'#231f20','headertext':'#ffffff','background':'#1c1908','subhd':'#877f5b','subhdtext':'#ffffff','inputs':'#9ebbc5','inputtext':'#ffffff','date':'#ffffff','links':'#c2effe','textColor':'#ffffff'},
		/*10-gnarls*/		{'highlights':'#00b9d8','lowlights':'#231f20','headertext':'#ffffff','background':'#95795b','subhd':'#00b9d8','subhdtext':'#00b9d8','inputs':'#00b9d9','inputtext':'#ffffff','date':'#999999','links':'#95d7eb','textColor':'#ffffff'},
		/*11-missy*/		{'highlights':'#e7e2c3','lowlights':'#abbabd','headertext':'#ffffff','background':'#ffffff','subhd':'#e7e2c3','subhdtext':'#4f4c4d','inputs':'#e7e2c3','inputtext':'#333333','date':'#999999','links':'#4f4c4d','textColor':'#000000'},
		/*12-plies*/		{'highlights':'#877f5b','lowlights':'#231f20','headertext':'#ffffff','background':'#000000','subhd':'#877f5b','subhdtext':'#ffffff','inputs':'#877f5b','inputtext':'#ffffff','date':'#999999','links':'#9ebbc5','textColor':'#ffffff'},
		/*13-prettyricky*/	{'highlights':'#d41410','lowlights':'#000000','headertext':'#ffffff','background':'#000000','subhd':'#666666','subhdtext':'#ffffff','inputs':'#333333','inputtext':'#333333','date':'#999999','links':'#d41410','textColor':'#ffffff'},
		/*14-t.i.*/			{'highlights':'#5e8ea3','lowlights':'#231f20','headertext':'#ffffff','background':'#242526','subhd':'#5e8ea3','subhdtext':'#ffffff','inputs':'#5e8ea3','inputtext':'#ffffff','date':'#5e8ea3','links':'#5e8ea3','textColor':'#ffffff'},
		/*15-operator*/		{'highlights':'#8fccac','lowlights':'#231f20','headertext':'#ffffff','background':'#000000','subhd':'#416050','subhdtext':'#ffffff','inputs':'#8fccac','inputtext':'#ffffff','date':'#999999','links':'#8fccac','textColor':'#ffffff'},
		/*16-kidrock*/		{'highlights':'#c2b494','lowlights':'#2e271c','headertext':'#ffffff','background':'#000000','subhd':'#6e664f','subhdtext':'#ffffff','inputs':'#6e664f','inputtext':'#ffffff','date':'#999999','links':'#c2b494','textColor':'#ffffff'},
		/*17-jamesblunt*/	{'highlights':'#3f6f7e','lowlights':'#231f20','headertext':'#ffffff','background':'#0c0c0c','subhd':'#3f6f7e','subhdtext':'#ffffff','inputs':'#3f6f7e','inputtext':'#ffffff','date':'#999999','links':'#c5e8f3','textColor':'#ffffff'},
		/*18-louisxiv*/		{'highlights':'#8fccac','lowlights':'#231f20','headertext':'#ffffff','background':'#b5ebc3','subhd':'#416050','subhdtext':'#ffffff','inputs':'#416050','inputtext':'#ffffff','date':'#ffffff','links':'#2d4a3b','textColor':'#231f20'},
		/*19-matchbox*/		{'highlights':'#3f6f7e','lowlights':'#716863','headertext':'#ffffff','background':'#e4e9e5','subhd':'#a3c8c1','subhdtext':'#ffffff','inputs':'#3f6f7e','inputtext':'#ffffff','date':'#999999','links':'#3f6f7e','textColor':'#748d88'},
		/*20-seanpaul*/		{'highlights':'#b94c06','lowlights':'#231f20','headertext':'#ffffff','background':'#000000','subhd':'#b94c06','subhdtext':'#ffffff','inputs':'#b94c06','inputtext':'#ffffff','date':'#ffffff','links':'#f1b64f','textColor':'#ffffff'},
		/*21-simpleplan*/	{'highlights':'#79662e','lowlights':'#231f20','headertext':'#ffffff','background':'#000000','subhd':'#79662e','subhdtext':'#ffffff','inputs':'#79662e','inputtext':'#ffffff','date':'#999999','links':'#78662e','textColor':'#ffffff'},
		/*22-treysongz*/	{'highlights':'#bea89b','lowlights':'#231f20','headertext':'#ffffff','background':'#d6d7d7','subhd':'#4c3d4c','subhdtext':'#ffffff','inputs':'#bea89b','inputtext':'#ffffff','date':'#999999','links':'#4c3d4c','textColor':'#666666'},
		/*23-twista*/		{'highlights':'#d81831','lowlights':'#231f20','headertext':'#ffffff','background':'#000000','subhd':'#ff9933','subhdtext':'#ffffff','inputs':'#ff9933','inputtext':'#ffffff','date':'#999999','links':'#ff9933','textColor':'#ffffff'},
		/*24-maleek*/		{'highlights':'#3f7c63','lowlights':'#050b11','headertext':'#ffffff','background':'#263442','subhd':'#3f7c63','subhdtext':'#ffffff','inputs':'#015b52','inputtext':'#ffffff','date':'#999999','links':'#9feba3','textColor':'#ffffff'},
		/*25-kekepalmer*/	{'highlights':'#cd8ca0','lowlights':'#6b1c22','headertext':'#ed5d68','background':'#021417','subhd':'#aa4c5d','subhdtext':'#ffffff','inputs':'#aa4c5d','inputtext':'#ffffff','date':'#ffffff','links':'#ffe0e2','textColor':'#ffffff'}
	),

	doSIFR: function(schemeId,targetId) {
		if(typeof sIFR == "function"){
			/*var headers = document.getElementsByClassName('sifr sIFR-replaced');
			for (var i=0; i<headers.length; i++) {
				headers[i].className = 'sifr';
			}
			var subheaders = document.getElementsByClassName('sifrSub sIFR-replaced');
			for (var i=0; i<subheaders.length; i++) {
				subheaders[i].className = 'sifrSub';
			}*/
			var h1Template = named({sFlashSrc: "/images/futura_bold.swf", sColor: "#FFFFFF", sBgColor: this.skins[schemeId-1].lowlights, sWmode: 'opaque', sCase: "upper", sFlashVars:"offsetLeft=6"});
			var h1SubTemplate = named({sFlashSrc: "/images/futura_expanded.swf", sColor: this.skins[schemeId-1].subhdtext, sBgColor: this.skins[schemeId-1].subhd, sWmode: 'opaque', sCase: "upper", sFlashVars:"offsetLeft=6"});
			var h4Template = named({sFlashSrc: "/images/futura_bold.swf", sColor: "#FFFFFF", sBgColor: this.skins[schemeId-1].lowlights, sWmode: 'opaque', sCase: "upper"});
			if (targetId=='h1.sifrSub') {
				sIFR.replaceElement(targetId,h1SubTemplate);
			} else {
				sIFR.replaceElement("h1.sifr", h1Template);
				sIFR.replaceElement("b.sifr", h1Template);
				sIFR.replaceElement("b.youmay", h1Template);
				sIFR.replaceElement("h1.sifrSub",h1SubTemplate);
				sIFR.replaceElement("h4.sifr", h4Template);
			}
		};
	},
	swapSchemeId: function(str, schemeId) {
		var schemesIndex = str.indexOf('bgschemes/');
		var imgIndex = str.indexOf('/', schemesIndex+10);
		if (schemesIndex > -1) { str = str.substring(0,schemesIndex+10) + schemeId + str.substring(imgIndex); }
		return str;
	}
	
};
function onFSCommand(methodName, args) {
	// appease the Brightcove MONSTER
}
function formatDate() {}


var fave = 1;
var specialScheme = 0;
var colorized = false;

$(document).ready(function() {

	// remove empty tr's
	var tr = $('tr td.line:empty').parent().remove();
	/*for (var i=0; i<tr.length; i++) {
		if (tr[i].innerHTML=='<td class="line"></td>' || tr[i].innerHTML=='<td class="line" colspan="3"></td>' || tr[i].innerHTML=='<td class=line></td>') {
			$(tr[i]).remove();
		}
	}*/
	// global
	$('table.wba_main_table').attr({'width':'950'});
	$('td.wba_topnavBG').parent().remove();
	// move store nav
	$('table:first').after($('table.logo'));
	$('td#wba_logo_bg').parent().remove();
	// title of artist list
	$('#wba_greyBar_foot .wba_ProductBar').wrapInner('<div class="headerbox"><div></div></div>');
	$('#wba_greyBar_foot .wba_ProductBar b.green').replaceWith('<h1 class="sifr">ARTISTS</h1>');
	
	
	// change all cellspacing
	$('table[cellspacing=7]').attr({'cellspacing':'0'});
	$('table.wba_main_table>tbody>tr>td').css('padding',0);
	$('body>table>tbody>tr>td').css('padding',0);
	
	// remove more empty tr's in the nav
	tr = $('td.menubar-label').parent();
	// move recently viewed on subpages into main column
	$('td.hideme').next().append($('td#wba_greyBar_foot table.wba_prod_widget'));
	
	
	// Page Specific 
	$('td.wba_Bar').attr({'style':''}); // first clear out the style
	if ($('span.crumbHome').size()==0) {
		/******** HOME PAGE ONLY *********/
		$('td.wba_Bar').wrapInner('<div class="headerbox"><div class="main"></div></div>');
		
		// Adjust Featured Products and Best Sellers so that Title goes below image
		$('table.wba_prod_widget:lt(2) a.homeProductTitle').parent().each(function() {
			$(this).parent().next().children().prepend($(this).html());
			$(this).remove();
		});
		$('table.wba_prod_widget:lt(2)a img.wba_add_to_cart_btn').each(function() {
			$(this).parent().parent().attr('align','left');
			$(this).parent().parent().parent().parent().append($(this).parent().parent());
			$(this).parent().parent().wrap('<tr valign="top"></tr>');
		});
		$('table.wba_prod_widget:lt(2) img[title=Details]').each(function() {
			$(this).parent().parent().attr('align','left');
			$(this).parent().parent().parent().parent().append($(this).parent().parent());
			$(this).parent().parent().wrap('<tr valign="top"></tr>')
		});
		
		// For Recently Viewed, move title and buylinks to right side
		$('table.wba_prod_widget:eq(2)').each(function () {
			$(this).find('table>tbody>tr>td').attr('align','left');
			$(this).find('tr:gt(0) table table').each(function () {
			$(this).appendTo($(this).parent().parent().prev().children('td'));
			$(this).parent().appendTo($(this).parent().parent().prev());
			});
		});
		
		// Home page background positioning is different b/c no breadcrumb trail
		$('table.wba_main_table').css('background-image','url('+storeBGUrl+')').css('background-position','50% -241px').css('background-repeat','no-repeat');
		$('tr.lightGreyBar').css('background-image','url('+storeBGUrl+')').css('background-position','50% -241px').css('background-repeat','no-repeat');
		$('tr#wba_prod_page_lightGreyBar').css('background-image','url('+storeBGUrl+')').css('background-position','50% -241px').css('background-repeat','no-repeat');
		$('div#flash-header').css('background-image','url('+storeBGUrl+')').css('background-position','50% -60px');
		
		$('table.wba_main_table>tbody>tr>td>table>tbody>tr>td>table[width=100%]').attr('width','560');
	} else {
		$('td.wba_Bar').wrapInner('<div class="headerbox"><div></div></div>');
		$('table.wba_prod_widget').find('td[align=center]').attr({'align':'left'});
		
		// Background graphic
		$('table.wba_main_table').css('background-image','url('+storeBGUrl+')').css('background-position','50% -220px').css('background-repeat','no-repeat');
		$('tr.lightGreyBar').css('background-image','url('+storeBGUrl+')').css('background-position','50% -220px').css('background-repeat','no-repeat');
		$('tr#wba_prod_page_lightGreyBar').css('background-image','url('+storeBGUrl+')').css('background-position','50% -220px').css('background-repeat','no-repeat');
		$('div#flash-header').css('background-image','url('+storeBGUrl+')').css('background-position','50% -40px');
		
		//if (typeof(wba_confirmation) == 'undefined') {
			/* Rearrange contents of Product Modules */
			$('table.wba_prod_widget:eq(0)').each(function () {
				$(this).find('tr:gt(0) table table').each(function () {
					$(this).appendTo($(this).parent().parent().prev().children('td'));
					$(this).parent().appendTo($(this).parent().parent().prev());
				});
			});

		$('table.wba_prod_widget:eq(1)').each(function () {
				$(this).find('tr:gt(0) table table').each(function () {
					$(this).appendTo($(this).parent().parent().prev().children('td'));
					$(this).parent().appendTo($(this).parent().parent().prev());
				});
		});

	//	}
		/******* CONTENT / MERCHANT PAGES *******/
		if (typeof(wba_category) == 'undefined' && typeof(wba_product) == 'undefined') {

		} else {
			if (typeof(wba_category) != 'undefined' || $('title').text().indexOf('Search Results')>=0) {
				/******* CATEGORY PAGES *******/
				$('td.hideme').prepend('<div class="headerbox"><div><h1 class="sifr">'+wba_category.name+'</h1></div></div>');
				$('#sortByHeader').append('SORTED BY: '+$($('select#sortBySelect option:selected')[0]).text());
				$('td.binHead b').addClass('sifr');
				$('td.binHead').wrapInner('<div class="headerbox"><div></div></div>');
				
				/* Remove redundant categories menu */
				if (wba_category.name=='Video/DVD' || wba_category.name=='Books') {
					while ($('tr td.binHead:first').parent().prev().size() > 0) {
						$('tr td.binHead:first').parent().prev().remove();
					}
					$('td.hideme div.headerbox:first').remove();
				}
			}
			if (typeof(wba_product) != 'undefined') {
				/******* PRODUCT PAGE *******/
				$('table.wba_main_table table table table:eq(2)').attr({'width':'90%','align':'center'});
				$('tr#wba_prod_page_lightGreyBar').next().find('>td>table>tbody>tr>td>table[width=100%]').attr('width',560);
			}
		}
	}
	
	
	$('td.hideme b.green').addClass('sifr');
	$('td.hideme b.green').removeClass('green');
	$('td.wba_Bar b.green').addClass('sifr');
	$('td.wba_Bar b.green').removeClass('green');
	
	// remove extra pixel 
	$('img[height=1]').remove();
	$('table.wba_prod_widget:first').prev('img').remove();
	$('table.wba_prod_widget:last>table').css({'width':'542px', 'marginLeft': '6px'});
	
	
	// Clean up Footer
	$('#wba_footer_1 td:first').next().remove();
	$('#wba_footer_1').next().remove();
	$('tr#wba_footer_1 td').attr('valign','middle');
	var copyright = $('#wba_footer_2 td.footer').html();
	//$('#wba_footer_1 td:first').prepend(copyright);
	$('#wba_footer_2').remove();
	
	// Remove empty TR's and TD's
	/*var rmTds = $('td.hideme table:first tr');
	for (var i=0; i<4; i++) {
		$(rmTds[i]).remove();
	}*/
	$('td.lightGreyBar').parent().remove();
	$('tr.greyBar').remove(); // remove extra category name and pagination
	
	
	// Update star graphics
	$('div.stars-0-0 img').attr({'src':'/images/atlantic_stars_0_0.gif'});
	$('div.stars-0-5 img').attr({'src':'/images/atlantic_stars_0_5.gif'});
	$('div.stars-1-0 img').attr({'src':'/images/atlantic_stars_1_0.gif'});
	$('div.stars-1-5 img').attr({'src':'/images/atlantic_stars_1_5.gif'});
	$('div.stars-2-0 img').attr({'src':'/images/atlantic_stars_2_0.gif'});
	$('div.stars-2-5 img').attr({'src':'/images/atlantic_stars_2_5.gif'});
	$('div.stars-3-0 img').attr({'src':'/images/atlantic_stars_3_0.gif'});
	$('div.stars-3-5 img').attr({'src':'/images/atlantic_stars_3_5.gif'});
	$('div.stars-4-0 img').attr({'src':'/images/atlantic_stars_4_0.gif'});
	$('div.stars-4-5 img').attr({'src':'/images/atlantic_stars_4_5.gif'});
	$('div.stars-5-0 img').attr({'src':'/images/atlantic_stars_5_0.gif'});
	$("img[src*='stars-0-0']").attr('src','/images/atlantic_stars_0_0.gif');
	$("img[src*='stars-0-5']").attr('src','/images/atlantic_stars_0_5.gif');
	$("img[src*='stars-1-0']").attr('src','/images/atlantic_stars_1_0.gif');
	$("img[src*='stars-1-5']").attr('src','/images/atlantic_stars_1_5.gif');
	$("img[src*='stars-2-0']").attr('src','/images/atlantic_stars_2_0.gif');
	$("img[src*='stars-2-5']").attr('src','/images/atlantic_stars_2_5.gif');
	$("img[src*='stars-3-0']").attr('src','/images/atlantic_stars_3_0.gif');
	$("img[src*='stars-3-5']").attr('src','/images/atlantic_stars_3_5.gif');
	$("img[src*='stars-4-0']").attr('src','/images/atlantic_stars_4_0.gif');
	$("img[src*='stars-4-5']").attr('src','/images/atlantic_stars_4_5.gif');
	$("img[src*='stars-5-0']").attr('src','/images/atlantic_stars_5_0.gif');
	
	$("img[src*='atlantic_btn_continueshopping.gif']").attr({'width':152,'height':20});
	/*if ($.browser.msie && $.browser.version < 7) {
		$('img.
	FILTER: progid:DXImageTransform.Microsoft.AlphaImageLoader(src="http://atl.amazonwebstore.com/shared/images/stars-3-0.png",sizingMethod="scale")
	*/
	// Global
	// move the left column
	$('table.wba_main_table table:first td:first').prepend($('div#leftcolumn'));
	
	/* on pages where the prod widgets are at the bottom, move into left column */
	if ($('table.wba_main_table>tbody>tr:gt(1) table.wba_prod_widget').size() > 0) {
		$('table.wba_main_table>tbody>tr:gt(1) table.wba_prod_widget').appendTo('div#leftcolumn');
	}
	
	SchemaSelector.doSIFR(fave);
});
