﻿var swfSrc = '';
var XMLsrc = '';
var teaserICO = '';
var teaserTitle = '';
var teaserText = '';
var TeaserLink = '';
var teaserWidth = '';
var teaserHeight = '';
var teaserData = new Object();
var randData = new Object();
var swfData = new Object();
var rand_no = Math.floor((2)*Math.random()) + 1;



function randObject(id){
//	rand_no = Math.floor((2)*Math.random()) + 1; 

	switch(id){
		case 1:
			if(rand_no == 1){
				teaserData = {
					teaserTarget:"",
					teaserOnClick:"",
					teaserICO:"./images/home/joy_icon.jpg",
					teaserTitle:"./images/home/joy_title.gif",
					teaserText:"Discover more reasons to<br/> buy MINI.",
					teaserLink:"html/about_us/reasons_to_buy.html?s3promobox=promobox"
				}
			}else{
				teaserData = {
					teaserTarget:"_blank",
					teaserOnClick:"tc_log('/home_teaser/facebook?s3promobox=facebook');",
					teaserICO:"images/home/facebook_ico.jpg",
					teaserTitle:"images/home/ttl_facebook.gif",
					teaserText:"Connect with fans, share<br/>stories and your best MINI-shots.",
					teaserLink:"http://www.facebook.com/home.php?#!/MINI.uk?v=app_10339498918&ref=ts"
				}
			}
		  break;
		case 2:
			if(rand_no == 1){
				teaserData = {
					teaserTarget:"",
					teaserOnClick:"",
					teaserICO:"./images/home/joy_icon.jpg",
					teaserTitle:"./images/home/joy_title.gif",
					teaserText:"Discover more reasons to<br/> buy MINI.",
					teaserLink:"html/about_us/reasons_to_buy.html?s3promobox=promobox"
				}
			}else{
				teaserData = {
					teaserTarget:"_blank",
					teaserOnClick:"tc_log('/home_teaser/facebook?s3promobox=facebook');",
					teaserICO:"images/home/facebook_ico.jpg",
					teaserTitle:"images/home/ttl_facebook.gif",
					teaserText:"Connect with fans, share<br/>stories and your best MINI-shots.",
					teaserLink:"http://www.facebook.com/home.php?#!/MINI.uk?v=app_10339498918&ref=ts"
				}
			}
		  break;
		case 3:
			if(rand_no == 1){
				teaserData = {
					teaserTarget:"",
					teaserOnClick:"",
					teaserICO:"./images/home/joy_icon.jpg",
					teaserTitle:"./images/home/joy_title.gif",
					teaserText:"Discover more reasons to<br/> buy MINI.",
					teaserLink:"html/about_us/reasons_to_buy.html?s3promobox=know_it_all"
				}
			}else{
				teaserData = {
					teaserTarget:"_blank",
					teaserOnClick:"tc_log('/home_teaser/facebook?s3promobox=facebook');",
					teaserICO:"images/home/facebook_ico.jpg",
					teaserTitle:"images/home/ttl_facebook.gif",
					teaserText:"Connect with fans, share<br/>stories and your best MINI-shots.",
					teaserLink:"http://www.facebook.com/home.php?#!/MINI.uk?v=app_10339498918&ref=ts"
				}
			}
		  break;
		case 4:
			if(rand_no == 1){
				teaserData = {
					teaserTarget:"",
					teaserOnClick:"",
					teaserICO:"./images/home/joy_icon.jpg",
					teaserTitle:"./images/home/joy_title.gif",
					teaserText:"Discover more reasons to<br/> buy MINI.",
					teaserLink:"html/about_us/reasons_to_buy.html?s3promobox=promobox"
				}
			}else{
				teaserData = {
					teaserTarget:"_blank",
					teaserOnClick:"tc_log('/home_teaser/facebook?s3promobox=facebook');",
					teaserICO:"images/home/facebook_ico.jpg",
					teaserTitle:"images/home/ttl_facebook.gif",
					teaserText:"Connect with fans, share<br/>stories and your best MINI-shots.",
					teaserLink:"http://www.facebook.com/home.php?#!/MINI.uk?v=app_10339498918&ref=ts"
				}
			}
		  break;
		case 5:
			if(rand_no == 1){
				teaserData = {
					teaserTarget:"",
					teaserOnClick:"",
					teaserICO:"./images/home/joy_icon.jpg",
					teaserTitle:"./images/home/joy_title.gif",
					teaserText:"Discover more reasons to<br/> buy MINI.",
					teaserLink:"html/about_us/reasons_to_buy.html?s3promobox=know_it_all"
				}
			}else{
				teaserData = {
					teaserTarget:"_blank",
					teaserOnClick:"tc_log('/home_teaser/facebook?s3promobox=facebook');",
					teaserICO:"images/home/facebook_ico.jpg",
					teaserTitle:"images/home/ttl_facebook.gif",
					teaserText:"Connect with fans, share<br/>stories and your best MINI-shots.",
					teaserLink:"http://www.facebook.com/home.php?#!/MINI.uk?v=app_10339498918&ref=ts"
				}
			}
		  break;
		case 6:
			if(rand_no == 1){
				teaserData = {
					teaserTarget:"",
					teaserOnClick:"",
					teaserICO:"./images/home/Graphite.jpg",
					teaserTitle:"./images/home/Graphite_title.jpg",
					teaserText:"Hurry, production ends soon.",
					teaserLink:"html/model_range/mini_graphite.html?s3promobox=graphite"
				}
			}else{
				teaserData = {
					teaserTarget:"",
					teaserOnClick:"",
					teaserICO:"./images/home/MINI-United-2009.jpg",
					teaserTitle:"./images/home/ttl_limited_edition.gif",
					teaserText:"MINI John Cooper Works <br/>World Championship 50.",
					teaserLink:"html/model_range/jcw_wc50.html?s3promobox=jcw_wc50"
				}
			}
		  break;
	}

	randData = teaserData;
	rendTeasers(id);
}

function randSWF(){	
	
	if(rand_no == 1){
		swfData = {
			flashVars:"",
			swfParamSrc:"./swf/home/teaser.swf?xmlPath=xml/home/content.xml",
			swfEmbedSrc:"./swf/home/teaser.swf?xmlPath=xml/home/content.xml",
			swfWidth:"757",
			swfHeight:"276"
		}
	}else{
		swfData = {
			flashVars:"",
			swfParamSrc:"./swf/home/teaser.swf?xmlPath=xml/home/content.xml",
			swfEmbedSrc:"./swf/home/teaser.swf?xmlPath=xml/home/content.xml",
			swfWidth:"757",
			swfHeight:"276"
		}
	}

	
	var swfEmbed = "<object align=\"top\" id=\"home\" height=\""+swfData.swfHeight+"\" width=\""+swfData.swfWidth+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" ";
	swfEmbed += "codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\">";
	swfEmbed += "<param name=\"movie\" value=\""+swfData.swfParamSrc+"\"><param name=\"quality\" value=\"best\">";
	swfEmbed += "<param name=\"wmode\" value=\"transparent\"><param name=\"FlashVars\" value=\""+swfData.flashVars+"\"> ";
	swfEmbed += "<embed src=\""+swfData.swfEmbedSrc+"\" FlashVars=\""+swfData.flashVars+"\" quality=\"best\" width=\""+swfData.swfWidth+"\" height=\""+swfData.swfHeight+"\" ";
	swfEmbed += "name=\"home\" align=\"top\" bgcolor=\"#000000\" wmode=\"transparent\" type=\"application/x-shockwave-flash\" ";
	swfEmbed += "pluginspage=\"http://www.macromedia.com/go/getflashplayer\"></embed></object><script type=\"text/javascript\" ";
	swfEmbed += "src=\"./scripts/enableActive.js\"> </script>";
	document.getElementById('main').innerHTML = swfEmbed;
}

function randTeaser(){
	var args = Array.prototype.slice.call(arguments); 
	// teaserTable
	for (var i=0; i<args.length; ++i){
		randObject(args[i]);
	}
}

function rendTeasers(id){
	var tTable = '<a href="'+randData.teaserLink+'" class="teaserLink" target="'+randData.teaserTarget+'" title="" onClick="'+randData.teaserOnClick+'"><img src="'+randData.teaserTitle+'" border="0"><div>'+randData.teaserText+'</div></a>';
	document.getElementById(('teaserTable'+id)).innerHTML = tTable;
	
	// teaserTableImg
	var tTableImg = '<a href="'+randData.teaserLink+'" class="teaserLink" target="'+randData.teaserTarget+'" title="" onClick="'+randData.teaserOnClick+'"><img src="'+randData.teaserICO+'" border="0"></a>';
	document.getElementById(('teaserTableImage'+id)).innerHTML = tTableImg;
}

function gotoURL(url){
	window.location = url;
}

