/* 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'}
	),

	switchSchema: function(schemeId) {
		//alert('switching schema to '+schemeId);
		//schemeId = (specialScheme==0) ? schemeId : specialScheme;
		if (colorized) { this.doSIFR(schemeId); } // only call this on subsequent calls, not 1st time
		
		// take care of the header box background color
		var rule = this.findCSSRule('headerbox');
		if (rule != null) { rule.style.backgroundColor = this.skins[schemeId-1].highlights; }
			
		// take care of buyit button class
		var buyit = this.findCSSRule('buyit');
		if (buyit != null) { buyit.style.backgroundImage = 'url(http://www.atlanticrecords.com/style/common/bgschemes/'+schemeId+'/btn_buyit.gif)'; }
		
		// take care of merchbox bold text class
		var merchtext = this.findCSSRule('merchbox b');
		if (merchtext != null) { merchtext.style.color = this.skins[schemeId-1].links; }
		
		// handle paging bar class
		var pagebar = this.findCSSRule('pagingbar');
		if (pagebar != null) { pagebar.style.backgroundColor = this.skins[schemeId-1].subhd; }
		
		// handle buttons
		var btns = this.findAllCSSRules('btn','background');
		for (var i=0; i<btns.length; i++) {
			if (btns[i].style.backgroundImage.substring(btns[i].style.backgroundImage.length-3) != 'png') {
				btns[i].style.backgroundImage = this.swapSchemeId(btns[i].style.backgroundImage, schemeId);
			}
		}
		
		// take care of the body background image
		/*var body = this.findCSSRule('body');
		if (body != null) {
			body.style.background = this.skins[schemeId-1].lowlights+" url('http://www.media.wmg-is.com/media/portal/media/cms/images/200809/t-i.-paper-trail-special-background-extralarge_1221251708281.jpg') no-repeat center 65px";
			body.style.color=this.skins[schemeId-1].textColor;
		} else { alert('couldn\'t find body'); }
		*/
		//var insidebody = this.findCSSRule('wba_main_table');
		//if (insidebody != null) { insidebody.style.background = this.skins[schemeId-1].background+" url('http://www.media.wmg-is.com/media/portal/media/cms/images/200809/t-i.-paper-trail-special-background-extralarge_1221251708281.jpg') no-repeat center -285px"; }
		
		
		
		// header front color
		var rule = this.findCSSRule('headerbox div');
		if (rule != null) { rule.style.backgroundColor = this.skins[schemeId-1].lowlights; }
		
		// do all sub navigation
		var subnavs = this.findAllCSSRules('subnav','background');// = findCSSRule('subnav-whatsinstore');
		for (var i=0; i<subnavs.length; i++) {
			subnavs[i].style.backgroundImage = this.swapSchemeId(subnavs[i].style.backgroundImage, schemeId);
		}
		
		// do all the subheaders
		var subhds = this.findAllCSSRules('subhead','background');
		for (var i=0; i<subhds.length; i++) {
			subhds[i].style.backgroundColor = this.skins[schemeId-1].subhd;
		}
		var subhds = this.findAllCSSRules('h1','background');
		for (var i=0; i<subhds.length; i++) {
			var bgUrl = subhds[i].style.backgroundImage;
			if (bgUrl.indexOf('http://www.atlanticrecords.com/style/common/') >= 0) {
				subhds[i].style.backgroundImage = this.swapSchemeId(bgUrl, schemeId);
			}
		}
		var loading = this.findCSSRule('div.loading');
		if (loading != null) { 
			loading.style.color = this.skins[schemeId-1].highlights;
		}
		
		// date color
		var rule = this.findCSSRule('div.newsdate');
		if (rule != null) { rule.style.color = this.skins[schemeId-1].date; }
		
		var links = this.findAllCSSRules('a:link','color');
		for (var i=0; i<links.length; i++) {
			links[i].style.color = this.skins[schemeId-1].links;
		}
		var links = this.findAllCSSRules('a:visited','color');
		for (var i=0; i<links.length; i++) {
			links[i].style.color = this.skins[schemeId-1].links;
		}
		var links = this.findAllCSSRules('a:hover','color');
		for (var i=0; i<links.length; i++) {
			links[i].style.color = this.skins[schemeId-1].links;
		}
		var head = this.findCSSRule('h2');
		if (head != null) { head.style.color = this.skins[schemeId-1].highlights; }
		
		var inputs = this.findAllCSSRules('input', 'color');
		for (var i=0; i<inputs.length; i++) {
			if (inputs[i].selectorText.indexOf('submit')<0 && inputs[i].selectorText.indexOf('radio')<0) {
				inputs[i].style.backgroundColor = this.skins[schemeId-1].inputs;
				inputs[i].style.color = this.skins[schemeId-1].inputtext;
			}
		}
		var submits = this.findAllCSSRules('img.submit', 'background');
		for (var i=0; i<submits.length; i++) {
			//alert(submits[i].selectorText);
			if (BrowserDetect.browser == 'Explorer' && BrowserDetect.version < 7) {
				submits[i].style.cssText += "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://www.atlanticrecords.com/style/common/bgschemes/"+schemeId+"/btn_go.png',sizingMethod='scale');";
			} else {
				submits[i].style.backgroundImage = "url(http://www.atlanticrecords.com/style/common/bgschemes/"+schemeId+"/btn_go.png)";
				submits[i].style.backgroundRepeat ="no-repeat";
			}
		}
		var radio = this.findCSSRule('input.radio');
		if (radio != null) { 
			radio.style.backgroundColor = this.skins[schemeId-1].background;
		}
		var checkbox = this.findCSSRule('div.checkbox input');
		if (checkbox != null) { 
			checkbox.style.backgroundColor = this.skins[schemeId-1].background;
		}
		var selectbox = this.findCSSRule('select');
		if (selectbox != null) { 
			selectbox.style.backgroundColor = this.skins[schemeId-1].background;
			selectbox.style.color = this.skins[schemeId-1].textColor;
		}
		
		var textarea = this.findCSSRule('textarea');
		if (textarea != null) { 
			textarea.style.backgroundColor = this.skins[schemeId-1].inputs;
			textarea.style.color = this.skins[schemeId-1].inputtext;
		}
		var rule = this.findCSSRule('hd-gethookedup img');
		if (rule != null) {
			if (BrowserDetect.browser == 'Explorer' && BrowserDetect.version < 7) {
				rule.style.cssText += "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://www.atlanticrecords.com/style/common/bgschemes/"+schemeId+"/2off.png',sizingMethod='scale');";
			} else {
				rule.style.backgroundImage = "url(http://www.atlanticrecords.com/style/common/bgschemes/"+schemeId+"/2off.png)";
				rule.style.backgroundRepeat ="no-repeat";
			}
		}
		
		CookieMonster.createCookie('favoriteSchema',schemeId,9999);
		colorized = true;
	},
	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("h1.sifrSub",h1SubTemplate);
				sIFR.replaceElement("h4.sifr", h4Template);
			}
		};
	},
	findCSSRule: function(selector) {
		if (!document.styleSheets) {return;}
		var theRules = new Array();
		for (var i=0; i<document.styleSheets.length; i++) {
			if (document.styleSheets[i].cssRules) {
				theRules = document.styleSheets[i].cssRules;
			} else if (document.styleSheets[i].rules) {
				theRules = document.styleSheets[i].rules;
			} else { return; }
			for (var j=0; j<theRules.length; j++) {
				if (theRules[j].selectorText != null) {
					if (theRules[j].selectorText.toLowerCase().indexOf(selector.toLowerCase()) >= 0) {
						return (theRules[j]);
					}
				}
			}
		}
		return null;
	},
	findAllCSSRules: function(selector, search) {
		if (!document.styleSheets) {return;}
		var results = new Array();
		var theRules = new Array();
		for (var i=0; i<document.styleSheets.length; i++) {
			if (document.styleSheets[i].cssRules) {
				theRules = document.styleSheets[i].cssRules;
			} else if (document.styleSheets[i].rules) {
				theRules = document.styleSheets[i].rules;
			} else { return; }
			for (var j=0; j<theRules.length; j++) {
				if (theRules[j].selectorText != null) {
					if (theRules[j].selectorText.toLowerCase().indexOf(selector) >= 0 && theRules[j].style.cssText.toUpperCase().indexOf(search.toUpperCase()) >= 0) {
						results.push(theRules[j]);
					}
				}
			}
		}
		return results;
	},
	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;
	}
	
};


var CookieMonster = {
	createCookie: function(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	},
	readCookie: function(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	},
	eraseCookie: function(name) {
		createCookie(name,"",-1);
	}
}

function onFSCommand(methodName, args) {
	// appease the Brightcove MONSTER
}

var fave = CookieMonster.readCookie('favoriteSchema');
if (fave == null) { fave = 1; }
var specialScheme = 0;
var colorized = false;

$(document).ready(function() {
	//$('tr td.line').parent().remove();
	/*var kids = $('td.hideme table tbody').children();
	$(kids[2]).remove();
	$(kids[0]).remove();
	*/
	var kids = $('tr.lightGreyBar');
	var tr = kids[0].nextSibling;
	$(tr).remove();
	tr = kids[0].nextSibling;
	var td = tr.firstChild;
	var table = td.firstChild;
	td.style.borderTop ='1px solid #222222';
	
	var tr = $('td.hideme table tbody').children();
	tr[0].firstChild.innerHTML = '<div class="headerbox"><div id="hd-categories"><h1 class="sifr">'+wba_category.name.toUpperCase()+'</h1></div></div>';
	
	//SchemaSelector.switchSchema(fave);
	/*var tds = getElementsByClassName({
		className: 'wba_main_table',
		tagName: 'table'
	});
	for (var i=0;i<tds.length;i++) {
		
	}*/
	SchemaSelector.doSIFR(fave);
});