/* 
   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/Global/Discoverdodge/working/8 2006/03/20 15:32:37 s42341i $
*/

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")
        
        if(site_config['site'] == 'int') {
	
			replaceFlash("/flash/globalNav_01.swf", "div.xx_header")
		}
	} else {
		//replaceImgs()
		replaceMessage()
	}
}	
	
function replaceFlash(flash_src, div_sel) {
	main_holder = document.getElementsBySelector(div_sel);
	globals = "";
	for(g in site_config) {
		globals += "&" + g + "=" + site_config[g];
	}
	if(site_config["is404"] ==  "true") {
		var assetSrc     = flash_src + '?src=404.html&lang=' + lang + globals;
	} else {
		var assetSrc     = flash_src + '?src=' + location.href + "&lang=" + lang + globals;
	}
	var assetWidth   = '100%';
	var assetHeight  = '100%';
	var assetBgcolor = '#f2f2f2';
	
	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';
	//~ alert(assetSrc)
	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="transparent"> \n';

	assetTag +='<embed \n';
	assetTag +=' src="' + assetSrc + '"\n';
	assetTag +=' width="' + assetWidth + '"\n';
	assetTag +=' height="' + assetHeight+ '"\n';
	assetTag +=' play="true" \n';
	assetTag +=' bgcolor="' + assetBgcolor + '" \n';
	assetTag +=' quality="high" \n';
    assetTag +=' wmode="transparent" \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;
	//alert(assetTag);
}

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 + "'>";
	}
	
}
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="/img/No_Flash.jpg" border="0"/></a>';
	main_holder[0].innerHTML = assetTag;
	main_holder[0].style.visibility = "visible"; 
}

