/*
Mentor home page random promotions

An unlimited amount of promotional images and links
can be added to the buildPromos() function.

All values must be used, they are:

imgname, Promotional image filename
link, The complete link for the image
category, The category that the promotion is in (techpub, event, or product)
height, Image height
width, Image width
location, Promo location, either upper area, lower right or lower left (upper, left, right)
*/

// randomizes an array
function randArray(myArray) {
	var i = myArray.length;
	while (i--){
		var j = Math.floor(Math.random() * (i+1));
		var tempi = myArray[i];
		var tempj = myArray[j];
		myArray[i] = tempj;
		myArray[j] = tempi;
	}
}
// put promos into an object and the object into the Promos array
function buildPromos(){
	Promos = new Array();
		var k=0;
		for (var i=0; i < arguments.length; i=i+6){
			Promos[k] = new Object();
			Promos[k].imgname = arguments[i];
			Promos[k].link = arguments[i+1];
			Promos[k].category = arguments[i+2];
			Promos[k].height = arguments[i+3];
			Promos[k].width = arguments[i+4];
			Promos[k].location = arguments[i+5];
			Promos[k].picked = false;
			k++
		}		
}
// individual promotion data
// imgname, link, category, height, width, location (left, right, upper)

// Removed from rotation to highlight Tech Forum Only
// 'br-product-cbasedpromo.gif', '/products/c-based_design/news/industryarticles.cfm', 'product', '152', '149', 'right',
// 'br-techpub-all.gif', '/training_and_services/tech_pubs.cfm', 'techpub', '152', '149', 'right',
// 'br-event-fv-seminar.gif', '/products/fv/events/verification_embedded_fpga_design_webcast.cfm?id=22481', 'event', '152', '149', 'right',
// 'bl-event-edatechforum.gif', '/events/techforum/', 'event', '136', '148', 'left',
// 'br-product-expedition.gif', '/products/pcb/expedition/demos/index.cfm', 'product', '152', '149', 'right',
// 'br-event-techForumKeynotes.gif', '/events/techforum/', 'product', '152', '149', 'right',

buildPromos(
'tl-techpub-all.gif', '/training_and_services/tech_pubs.cfm?isid=tl-techpub-all', 'techpub', '84', '177', 'upper',
'tl-event-all.gif', '/events/index.html', 'event', '84', '177', 'upper',
'bl-techpub-all.gif', '/techpaper/index.html', 'techpub', '136', '149', 'left',
'bl-product-calibrenmopc.gif','/products/ic_nanometer_design/mask_syn/calibre_nmopc/index.html','product', '136', '149', 'left',
'bl-product-rf.gif','/products/pcb/system_design/rf_design.html','products', '136', '149', 'left',
'bl-product-veloce_mitsubishi.gif','/products/fv/success/mitsubishi-success/index.html','products', '136', '149', 'left',
'bl-product-nmlvs_necel.gif','https://www.mentorg.co.jp/products/ic_nanometer_design/techpubs/index.html#IC Verification &amp; Signoff','products', '136', '149', 'left',
'bl-product-communities.gif','http://communities.mentor.com/mgcx/community/international_zone/japanese','products', '136', '149', 'left',
'br-product-ccs-systemc.gif','/products/esl/catapult-systemc/index.html','product', '152', '150', 'right',
'br-techpub-metastability.gif','/products/fv/techpubs/dvcon2008paper.html','techpub', '152', '150', 'right',
'br-product-supportnet.gif','http://supportnet.mentor.com/about_jp/tour.cfm','product', '152', '150', 'right',
'br-product-communities.gif','http://communities.mentor.com/mgcx/community/international_zone/japanese','product', '152', '150', 'right',
'br-product-nmlvs_necel.gif','https://www.mentorg.co.jp/products/ic_nanometer_design/techpubs/index.html#IC Verification &amp; Signoff','products', '152', '150', 'right',
'br-product-esl.gif','/products/esl/index.html','product', '152', '150', 'right'
);

 

randArray(Promos);

var upperPromo;
var rightPromo;
var leftPromo;

for (var i=0; i < Promos.length; i++){
	if (Promos[i].location == "upper"){
		upperPromo = Promos[i];
		for (var j=0; j < Promos.length; j++){
			if (Promos[j].category == upperPromo.category){
				Promos[j].picked = true;	
			}
		}
		break;
	}	
}

for (var i=0; i < Promos.length; i++){
	if (Promos[i].location == "right" && !Promos[i].picked){
		rightPromo = Promos[i];
		for (var j=0; j < Promos.length; j++){
			if (Promos[j].category == rightPromo.category){
				Promos[j].picked = true;	
			}
		}
		break;
	}	
}

for (var i=0; i < Promos.length; i++){
	if (Promos[i].location == "left" && !Promos[i].picked){
		leftPromo = Promos[i];
		break;
	}	
}

var output = new Array(upperPromo, rightPromo, leftPromo);
for (var i=0; i < output.length; i++){
	output[i] = '<a href="' + output[i].link + '"><img src="/mentor/images/promos/' + output[i].imgname + '" alt="" height="' + output[i].height + '" width="' + output[i].width + '" /></a>';
}

function outputPromo(which){
	document.write(output[which]);
}
