var rotate_speed=5000;
var times_to_cycle=3;

var current_media=0;
var timer;
var play='play';
var mouseover='play';
var media=[];
var ii=0;
var x=0;
var first_run=true;
var loop_count=1;
var so;
var banner_width=707;
var banner_height=212;

media[x++]='great_value';
media[x++]='mobile';
media[x++]='raf';

function show_media (id) {

	if (id!='save_money') {
		//flash_reset();
	}

	var previous_media=current_media;
	for (i=0;i<media.length;i++) {
		if (id==media[i]) {
			state='';
			imgsrc='_selected';
			current_media=i;
			color='#D98D00';
			weight='bold';
		} else {
			imgsrc='';
			state='none';
			color='#ffffff';
			weight='normal';
		}

		if (document.getElementById(media[i]).style.display!=state) {
			//if (document.getElementById(media[i]+'_flash').innerHTML=='') {
				//load_flash (current_media, banner_width, banner_height);
			//}
			document.getElementById(media[i]).style.display=state;
			document.getElementById('btn_'+media[i]).src='/images/homepage/btn_'+media[i]+imgsrc+'.gif';
			/*
			document.getElementById(media[i]+'_tab').style.color=color;
			document.getElementById(media[i]+'_tab').style.fontWeight=weight;
			*/
		}
	}



}


function rotate (action) {
	clearTimeout(timer);

	if (action=='toggle' || action=='pause') {
		if (play=='play' || action=='pause') {
			play='pause';
			document.getElementById('btn_pause').src='/images/homepage/btn_play.gif';
		} else {
			play='play';
			document.getElementById('btn_pause').src='/images/homepage/btn_pause.gif';
		}
	}

	if (action=='mouseover') {
		mouseover='pause';
	} else if (action=='mouseout') {
		mouseover='play';
	}

	if (play=='play' && mouseover=='play') {
		if (current_media>media.length-1) {
			current_media=0;
			if (loop_count++==times_to_cycle) {
				rotate ('pause');
			}
		}

		id=media[current_media];

		//load_flash (ii, banner_width, banner_height);


		ii++;

		if (action!='mouseout') {
			show_media(id);
			current_media++;
		}

		if (first_run) {
			first_run=false;
		}

		timer=setTimeout('rotate()',rotate_speed);
	}
	
}

function play_flash (){
	so = new SWFObject("/swf/saves_you_money.swf", "save_swf", "290", "166", "1");
	so.addParam("wmode", "transparent");
	so.write("save_money_flash");
}

function flash_reset () {
	document.getElementById('save_money_flash').innerHTML='<img src="/images/homepage/saves_you_money_flash.png" style="width:290px; height:166px; cursor:pointer;" onclick="play_flash();rotate(\'pause\');show_media(\'save_money\');hb_inline(\'save_money_video\');" />';
}


//Event.observe(window, 'load', rotate, true);
