var server = 'http://divx.adbureau.net/hserver/';
var last_swapped_on = 0;
var iframe;

function swap_ad(type) {
	var curdate = new Date();
	if ((curdate.getTime() / 1000) - last_swapped_on < 10) {
		return;
	}
	
	//Area var is printed in header
	ad_type = new Array();
	
	// Any changes in this switch should be replicated in Ad.php as well
	switch (type) {
    	case 'skyscraper':
			ad_type['width'] = '120';
			ad_type['height'] = '600';
			aamsz = ad_type['width'] + 'x' + ad_type['height'];
            break;
    	case 'leaderboard':
			ad_type['width'] = '728';
			ad_type['height'] = '90';
			aamsz = ad_type['width'] + 'x' + ad_type['height'];
            break;
        case 'mrec':
			ad_type['width'] = '300';
			ad_type['height'] = '250';
			aamsz = 'MREC';
            break;
		case 'postplate':
			ad_type['width'] = '300';
			ad_type['height'] = '250';
			aamsz = 's6postplate';
            break;
		case 'spotlight-banner':
			ad_type['width'] = '645';
			ad_type['height'] = '72';
			aamsz = 'vsheader';
            break;
    }

	if (iframe) {
		var url = server + 'SITE=STAGE6/' + ad_params + '/AAMSZ=' + aamsz + '/random=' + Math.floor(Math.random() * 100000);
		$('ad_container').innerHTML = "";
		create_iframe(type, ad_type['width'], ad_type['height'], url);
		last_swapped_on = curdate.getTime() / 1000;
	}
}

function post_plate(div){
	var type = new Array();
	type['name'] = 'post_plate';
	type['width'] = '300';
	type['height'] = '250';
	
	var url = server + 'SITE=STAGE6/' + ad_params + '/AAMSZ=' + type['width'] + 'x' + type['height'] + '/random=' + Math.floor(Math.random() * 100000);
	
	var iframe = Builder.node('iframe', {id:'ad_' + type['name'], src:url,  width:type['width'], height:type['height'], border:'0', scrolling:'no', marginwidth:'0', marginheight:'0', allowtransparency:'true', style:'background-color:#000;border:none;'});

	$(div).appendChild(iframe);
}

function create_iframe(type, width, height, src) {
	var temp_iframe = Builder.node('iframe', {id:'ad_' + type, src:src,  width:width, height:height, frameborder:'0', border:'0', scrolling:'no', marginwidth:'0', marginheight:'0', allowtransparency:'true', style:'background-color:#000;border:none;'});
	iframe = $('ad_container').appendChild(temp_iframe);
}

