//alert("johnny5");

/* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
            REAL CODE
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */

/* Asset root */
var asset_root = "http://www.dodge.com/myspace/nitro_customizer/";

/* Color palette */
var color_palette = new Array();
color_palette[1] = 'AF080F';
color_palette[2] = '000000';
color_palette[3] = 'C8C8C8';
color_palette[4] = 'C9540F';
color_palette[5] = '104B93';
color_palette[6] = 'A4A4A4';
color_palette[7] = '908066';
color_palette[8] = 'FFFFFF';
color_palette[9] = 'AF080F';
color_palette[10] = 'AF080F';
color_palette[11] = '104B93';

/* User selections */
var user_selections = new Object();
user_selections.bg_pattern	= 4;
user_selections.cs_image	= 6;
user_selections.bs_color	= 1;
user_selections.bs_pattern	= 6;
user_selections.fs_header	= 8;
user_selections.fs_body		= 8;
user_selections.fs_link		= 1;
user_selections.fs_rollover	= 6;


/* Tracking */
function track(argLid, argLpos){
    _hbSet('lid', argLid);
    _hbSet('lpos', argLpos);
    _hbSend();
}


/* Listen for and handle calls from Flash to change user selection
	prop_name:String	= human readable name of property to change (ie: bg_pattern)
	prop_val:Integer	= numeric selection of style values to apply
*/

function changeStyle(prop_name, prop_val) {
	//alert(prop_name + ":\n" + prop_val);
	user_selections[prop_name] = prop_val;
	chooseStyle(prop_name, prop_val)
	//Try to make Firefox not need its style drawn in page
	redrawStyle();
  track(prop_val, prop_name);
	
}

/* Redraws the style elemtents of the current page */
function redrawStyle() {
	/* Dump user selection values
	alert(
		user_selections.bg_pattern + ":\n" + 
		user_selections.cs_image + ":\n" + 
		user_selections.bs_color + ":\n" + 
		user_selections.bs_pattern + ":\n" + 
		user_selections.fs_header + ":\n" +	
		user_selections.fs_body + ":\n" +	
		user_selections.fs_link + ":\n" + 
		user_selections.fs_rollover
	);
	*/
	
	style_div = document.getElementById("style_holder")
	style_div.value= getStyleBlock();

}

/* Returns a formatted block of CSS style for injection into the page and cut and paste usage for user profiles */
function getStyleBlock() {
	
	css_block = "<style type='text/css'>\n";
	
	/* Get user selected values */
	css_block += getBGPattern();
	css_block += getCSImage();
	css_block += getBSColor();
	css_block += getBSPattern();
	css_block += getFSHeader();
	css_block += getFSBody();
	css_block += getFSLink();
	css_block += getFSRollover();
	
	/* Base CSS Properties */
	css_block += "body {\n" +
	"	background-position:Top Left; \n" +
	"}\n" +
	"\n" +
	"table table table { \n" +
	"	width: 400px;\n" +
	"}\n" +
	"\n" +
	"td.text td.text span.orangetext15, .heading{\n" +
	"	height: 29px;\n" +
	"	display: block;\n" +
	"	padding: 3px;\n" +
	"	background-repeat:repeat-x;\n" +
	"}\n" +
	"\n" +
	".contactTable {\n" +
	"	width:314px !important;\n" +
	"	height:178px !important;\n" +
	"	padding:0px !important;\n" +
	"	background-attachment:scroll; \n" +
	"	background-position:0 0;\n" +
	"	background-repeat:no-repeat; \n" +
	"	background-color:transparent; border:0px;\n" +
	"}\n" +
	"\n" +
	".contactTable a {\n" +
	"	display:block;\n" +
	"}\n" +
	"\n" +
	"table, td, table table table table {\n" +
	"	width:auto;\n" +
	"}\n" +
	"\n" +
	".contactTable table, table.contactTable td, table table table table {\n" +
	"	vertical-align:top;\n" +
	"	width: 100%;\n" +
	"	text-align:left;\n" +
	"	padding:0px !important;\n" +
	"	border:0px; \n" +
	"	background-color:transparent; \n" +
	"	background-image:none;\n" +
	"}\n" +
	"\n" +
	".contactTable a img {\n" +
	"	visibility:hidden; \n" +
	"	border:0px !important;\n" +
	"}\n" +
	"\n" +
	".contactTable .text {\n" +
	"	font-size:1px !important;\n" +
	"}\n" +
	"\n" +
	".contactTable .text, .contactTable a, .contactTable img {\n" +
	"	filter:none !important;\n" +
	"}\n" +
	"\n" +
	".contactTable .whitetext12 {\n" +
	"	display:none;\n" +
	"}\n" +
	"\n" +
	"table, td, tr, table td, table table table table, table table table td, table table table table table td, table table table table table{ \n" +
	"	border-style:none; \n" +
	"	background-color: transparent;\n" +
	"}\n" +
	"\n" +
	"table table table{\n" +
	"	padding: 7px;\n" +
	"}\n" +
	"\n" +
	".heading {\n" +
	"	width: 100%\n" +
	"	padding: 0px;\n" +
	"}\n" +
	"\n" +
	"td.text table, table table table table{\n" +
	"	padding: 0px;\n" +
	"}\n" +
	"\n" +
	"td.text td.text span.orangetext15, .heading{\n" +
	"	color: FFFFFF;\n" +
	"}\n" +
	"\n" +
	".blacktext12 {\n" +
	"	display:block; \n" +
	"	color:transparent; \n" +
	"	font-size:0px; \n" +
	"	height:77px; width:396px;\n" +
	"	background-image:url('" + asset_root + "imgs/leavebehind_banner_small.jpg')\n" +
	"}\n" +
	"\n" +
	"table table table[height='77']{ \n" +
	"	background-color:transparent;\n" +
	"	background-image:url('" + asset_root + "imgs/leavebehind_banner_small.jpg'); \n" +
	"	background-position:center; \n" +
	"	background-repeat:no-repeat;\n" +
	"}\n";
	
	css_block += "</style>";
	return css_block;
}

/* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
   CSS funcs for property types
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */

function getBGPattern() {
	var bg_pattern = "body{\n";

	switch (parseInt(user_selections.bg_pattern)) {
		case 20:
		bg_pattern +=  "	background-image:url('"+ asset_root +"patterns/tile_" + user_selections.bg_pattern + ".jpg');\n";
		break;
		
		default:
		bg_pattern +=  "	background-image:url('"+ asset_root +"patterns/tile_" + user_selections.bg_pattern + ".gif');\n";
		break;
	}

	switch (parseInt(user_selections.bg_pattern)) {
		case 3:
		bg_pattern += "	background-color:151515;\n" +
		"	background-repeat:repeat-x;\n";
		break;
		
		case 4:
		bg_pattern += "	background-color:D8D8D8;\n" +
		"	background-repeat:repeat-x;\n";
		break;

		case 20:
		bg_pattern += "	background-color:2B2B2B;\n" +
		"	background-repeat:no-repeat;\n" +
		"	background-attachment:fixed;\n" +
		"	background-position:top right;\n";
		
		break;
	}
	
	bg_pattern += "}\n";
	
	return bg_pattern;
}

function getCSImage() {
	var cs_image = ".contactTable {\n";
	"	background-image:url('" + asset_root + "imgs/cs_img_" + user_selections.cs_image + ".gif');\n" +
	"}\n" +
	"\n" +
	".contactTable a {\n" +
	//"	border: 1px solid #ff00ff;\n" + 
	"	width:150px;\n";
	
	switch (parseInt(user_selections.cs_image)) {
		case 3:
		case 4:
		case 7:
		case 8:
		case 9:
		cs_image += "	height:28px;\n";
		break;
		
		case 5:
		case 6:
		cs_image += "	height:33px;\n";
		break;
		
		default:
		cs_image += "	height:31px;\n";
		break;
	}
	cs_image += "}\n";
	
	return cs_image;
}

function getBSColor() {
//	var bs_color = "table table table, #profile_nitro_about, #profile_nitro_blog, #profile_comments, #profile_friends {\n" +
	var bs_color = "table table table {\n" +
	"	border: 1px solid;\n" +
	"	border-color: " + color_palette[user_selections.bs_color] + ";\n" +
	"}\n" +
	"\n" +
	"td.text td.text span.orangetext15, .heading{\n" +
	"	background-image:url('" + asset_root + "patterns/headerblock_tile_" + user_selections.bs_color + ".gif');\n" +
	"	background-repeat: repeat-x;\n" +
	"	background-position: right;\n" +
	"}\n";
	
	return bs_color;
	
}

function getBSPattern() {
//	var bs_pattern = "table table table, #profile_nitro_about, #profile_nitro_blog, #profile_comments, #profile_friends {\n" +
	var bs_pattern = "table table table {\n";
	
	switch (parseInt(user_selections.bs_pattern)) {
		case 20:
		bs_pattern += "	background-image:url('"+ asset_root +"patterns/tile_" + user_selections.bs_pattern + ".jpg');\n";
		break;
		
		default:
		bs_pattern += "	background-image:url('"+ asset_root +"patterns/tile_" + user_selections.bs_pattern + ".gif');\n";
		break;
	}
	
	


	switch (parseInt(user_selections.bs_pattern)) {
		case 3:
		bs_pattern += "	background-color:151515;\n" +
		"	background-repeat:repeat-x;\n";
		break;
		
		case 4:
		bg_pattern += "	background-color:D8D8D8;\n" +
		"	background-repeat:repeat-x;\n";
		break;

		case 20:
		bg_pattern += "	background-color:2B2B2B;\n" +
		"	background-repeat:no-repeat;\n" +
		"	background-attachment:fixed;\n" +
		"	background-position:top right;\n";
		
		break;
		
	}
	
	bs_pattern += "}\n";
	
	return bs_pattern;
	
}

function getFSHeader() {
	var fs_header = ".lightbluetext8, span.orangetext15{\n" +
	"	color: " + color_palette[user_selections.fs_header] + ";\n" +
	"}\n";
	
	return fs_header;
}

function getFSBody() {
	var fs_body = "body, div, p, strong, td, .text, .blacktext10, .blacktext12, .whitetext12, .whitetext10, .btext, .nametext, a.searchlinkSmall, a.searchlinkSmall:link, a.searchlinkSmall:visited{\n" +
	"	color:" + color_palette[user_selections.fs_body] + ";\n" + 
	"}\n";
	
	return fs_body;	
}

function getFSLink() {
	var fs_link = "a, a:link, a:visited, a.navbar, a.navbar:link, a.navbar:visited, a.man, a.man:link, a.man:visited, a.redlink, a.redlink:visited, a.redlink:link,  a.searchlinksmall, .lightbluetext8, .redbtext, span.orangetext15{ \n" +
	"	color:" + color_palette[user_selections.fs_link] + ";\n" + 
	"}\n";
	
	return fs_link;	
}

function getFSRollover() {
	var fs_rollover = "a:hover, a:active, a.navbar:hover, a.navbar:active, a.man:hover, a.man:active,  a.searchlinksmall:hover, a.searchlinksmall:active, a.redlink:hover{ \n" +
	"	color:" + color_palette[user_selections.fs_rollover] + ";\n" + 
	"}\n";
	
	return fs_rollover;	
}






/* Stylesheet switcher */

function setStylesheet(){ //Main stylesheet switcher function. Second parameter if defined causes a random alternate stylesheet (including none) to be enabled
	var i, cacheobj, altsheets=[""]
	for(i=0; (cacheobj=document.getElementsByTagName("link")[i]); i++) {
		if(cacheobj.getAttribute("rel").toLowerCase()=="alternate stylesheet" && cacheobj.getAttribute("title")) { //if this is an alternate stylesheet with title, turn it off
			cacheobj.disabled = true
			if(
				cacheobj.getAttribute("title") == "bg_pattern_" + user_selections.bg_pattern ||
				cacheobj.getAttribute("title") == "cs_image_" + user_selections.cs_image ||
				cacheobj.getAttribute("title") == "bs_color_" + user_selections.bs_color ||
				cacheobj.getAttribute("title") == "bs_pattern_" + user_selections.bs_pattern ||
				cacheobj.getAttribute("title") == "fs_header_" + user_selections.fs_header ||
				cacheobj.getAttribute("title") == "fs_body_" + user_selections.fs_body ||
				cacheobj.getAttribute("title") == "fs_link_" + user_selections.fs_link ||
				cacheobj.getAttribute("title") == "fs_rollover_" + user_selections.fs_rollover
			) 
			cacheobj.disabled = false //enable chosen style sheet
		}
	}
}

function chooseStyle(styletitle, styleid){ 
	if (BrowserDetect.browser != "MSIE" && BrowserDetect.browser != "Firefox"){
		setStylesheet(styletitle, styleid)
	}	

	for(i=0; (cacheobj=document.getElementById("page_style").getElementsByTagName("link")[i]); i++) {
		cacheobj.parentNode.removeChild(cacheobj)
	}

	loadobjs(
		asset_root + "css/bg_pattern_" + user_selections.bg_pattern + ".css",
		asset_root + "css/cs_image_" + user_selections.cs_image + ".css",
		asset_root + "css/bs_color_" + user_selections.bs_color + ".css",
		asset_root + "css/bs_pattern_" + user_selections.bs_pattern + ".css",
		asset_root + "css/fs_header_" + user_selections.fs_header + ".css",
		asset_root + "css/fs_body_" + user_selections.fs_body + ".css",
		asset_root + "css/fs_link_" + user_selections.fs_link + ".css",
		asset_root + "css/fs_rollover_" + user_selections.fs_rollover + ".css"
		);
}

function getCode() {
	code_div = document.getElementById("style_code");
	code_div.style.display = "block";
	track("get_code", "button");
	
}

function loadobjs(){
	if (!document.getElementById)
	return
	for (i=0; i<arguments.length; i++){
		var file=arguments[i]
		var fileref=""

		if (file.indexOf(".css")!=-1){ //If object is a css file
			fileref=document.createElement("link")
			fileref.setAttribute("rel", "stylesheet");
			fileref.setAttribute("type", "text/css");
			fileref.setAttribute("href", file);
		}

		if (fileref!=""){
			document.getElementById("page_style").appendChild(fileref)
		}
	}
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();



function nitroProfileInit() {
	if (arguments.callee.done) return;
	arguments.callee.done = true;
	
	if(BrowserDetect.browser != "Safari") {
		saf_styles=document.getElementById("safari_styles")
		saf_styles.parentNode.removeChild(saf_styles)
	}
	
	chooseStyle("bg_pattern", user_selections.bg_pattern)
	redrawStyle();
}


/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            REAL CODE
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */


/*
<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0' WIDTH='800' HEIGHT='375' id='nitro_masthead'>
<PARAM NAME=movie VALUE='http://www.dodge.com/myspace/nitro_customizer/swf/masthead.swf'>
<PARAM NAME=quality VALUE=high> 
<PARAM NAME=wmode VALUE=transparent>
<EMBED src='http://www.dodge.com/myspace/nitro_customizer/swf/masthead.swf' quality=high wmode=transparent WIDTH='800' HEIGHT='375' NAME='nitro_masthead' TYPE='application/x-shockwave-flash' PLUGINSPAGE='http://www.macromedia.com/go/getflashplayer'></EMBED>
</OBJECT><br />


<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0' WIDTH='830' HEIGHT='475' id='nitro_customizer'>
<PARAM NAME=movie VALUE='http://www.dodge.com/myspace/nitro_customizer/swf/mov100.swf'>
<PARAM NAME=quality VALUE=high>
<param name='AllowScriptAccess' value='always' />
<PARAM NAME=FlashVars VALUE='root_from_flashvars=http://www.dodge.com/myspace/nitro_customizer/'>
<PARAM NAME=wmode VALUE=transparent>
<EMBED src='http://www.dodge.com/myspace/nitro_customizer/swf/mov100.swf' quality=high wmode=transparent AllowScriptAccess='always' FlashVars='root_from_flashvars=http://www.dodge.com/myspace/nitro_customizer/' WIDTH='830' HEIGHT='475' NAME='nitro_customizer' TYPE='application/x-shockwave-flash' PLUGINSPAGE='http://www.macromedia.com/go/getflashplayer'></EMBED>
</OBJECT><br />

*/




