/* 
   Rewrites page data in the format <item class="img" src="x.jpg">alt text</item> into user viewable images.
	 Generates Interwoven Contextual Edit Bar-resistant HTML.
	 $Id: replace_assets.js /main/EU/Dodge/se/content/working/3 2008/02/22 05:10:27 iwovsys $
*/

var flash_override = false;	
if(location.search.length > 1) {
	flash_override = true;
}

function redrawSWFArea(h){
	main_swf = document.getElementsBySelector("div.content");
	main_swf[0].style.height = h + "px";
}

function replaceAssets(flash_src) {
	// replace any content-bar injected URLs with clean URLs:
	var url = new String( document.location );
	var no_injection_token = "/iw/cci/meta/no-injection";
	if( location.protocol != "file" && location.pathname.indexOf('/iw-mount') == 0 )
		location.replace( 
			location.protocol + "//" + location.host 
			+ (location.port ? ":" + location.port : "") 
			+ no_injection_token
			+ location.pathname + location.hash + location.search
		);

	if(hasFlash(7)){
		//replaceFlash("flash/globalNav_01.swf", "div.xx_header")
		replaceFlash(flash_src, "div.content")
	} else {
		//replaceImgs()
		replaceMessage();
	}
}	
	
function replaceFlash(flash_src, div_sel) {
	main_holder = document.getElementsBySelector(div_sel);
	
	globals = "";
	site_config["title"] = document.title;
	for(g in site_config) {
		globals += "&" + g + "=" + site_config[g];
	}
	
	var assetSrc     = flash_src + '?src=' + location.href + "&lang=" + lang + globals;
	var assetWidth   = '100%';
	var assetHeight  = '100%';
	var assetBgcolor = '#ffffff';
	
	assetTag ='<object \n';
	assetTag +='classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 \n';
	assetTag +='codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0 width="' + assetWidth + '" height="' + assetHeight + '"> \n';
	assetTag +='<param name=movie value="' + assetSrc + '"> \n';
	assetTag +='<param name=quality value="high"> \n';
	assetTag +='<param name=menu value="false"> \n';
	assetTag +='<param name="bgcolor" value="' + assetBgcolor + '"> \n';
	assetTag +='<param name="scale" value="noscale"> \n';
	assetTag +='<param name="wmode" value="opaque"> \n';
	assetTag +='<embed \n';
	assetTag +=' src="' + assetSrc + '"\n';
	assetTag +=' width="' + assetWidth + '"\n';
	assetTag +=' height="' + assetHeight+ '"\n';
	assetTag +=' play="true" \n';
	assetTag +=' wmode="opaque" \n';
	assetTag +=' bgcolor="' + assetBgcolor + '" \n';
	assetTag +=' quality="high" \n';
	assetTag +=' type="application/x-shockwave-flash" \n';
	assetTag +=' pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"> \n';
	assetTag +='</embed> \n';
	assetTag +='</object> \n';
	
	main_holder[0].innerHTML = assetTag;
	main_holder[0].style.visibility = "visible"; 
	//alert(assetSrc);
}


function replaceMessage(){
	main_holder = document.getElementsBySelector("div.content");
	assetTag ='<a href="javascript:flexWin(\'http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&P5_Language=English\',\'yes\',\'\',\'\',\'\',\'all\');"><img src="/image/' + site_config.vehicle + '/no-flash.jpg" border="0"/></a>';
	main_holder[0].innerHTML = assetTag;
	main_holder[0].style.visibility = "visible"; 
}

function replaceImgs() {
	var page_images = document.getElementsBySelector('div.img');
	for (var i=0;i<page_images.length;i++) {
		img_attr = page_images[i].getAttribute("src");
		img_alt = page_images[i].innerHTML;
		page_images[i].innerHTML = "<img src='" + img_attr + "' alt='" + img_alt + "'>";
	}
}


// hide XHTML content and flash styling data from javascript-enabled user agents 
// until content is loaded to avoid confusing the user with a partially loaded page:

var dc = document;
dc.write('<s' + 'tyl'+ 'e>.content{v' + 'isibi' + 'lity:h' + 'idden;}</st' + 'yle>');
//no new lines                 