
var orig_class = '';
var orig_tick = '';
var orig_text = '';
var isOn;
var t; //timer interval
var delay_interval = 3000;
var intro_count = 1;
var quote_count = 0;

/****** data *******
[0] = h1
[1] = p subtext
[2] = call to action text
[3] = alt/hover text
[4] = click url
[5] = color class
[6] = hover width for leftnav
******************/



function endFlash() {
	$('#flash_container').animate({opacity:0},500,function() {
		$('#flash_container').addClass('noshow');
		$('#leftnav').removeClass('noshow');
		$('#intro').removeClass('noshow');
		doTrans(1);
	});
}

function hoverOn(e) {
	orig_class = e.attr('class');
    orig_tick = e.find('img').attr('src');
    
    e.removeClass().addClass('gradient-orange-36');
    e.find("img").attr('src','/assets/templates/rce_business/images/tick-orange.png');
}

function hoverOff(e) {
	e.removeClass().addClass(orig_class);
	e.find("img").attr('src',orig_tick);
}



function openBlade(e) {
	//restore original color
	//e.removeClass().addClass(orig_class);
	//e.find("img").attr('src',orig_tick);
	//e.unbind('mouseenter mouseleave');
	
	//if (isOn != undefined && isOn != e.attr('id')) {closeBlade(isOn);}
	isOn = e.attr('id');
	
	var alt_text = e.find('span').attr('alt');
	orig_text = (isOn == "blade1") ? "Measure" : e.find('span').text();  //weird hack to catch auto open of 1st blade text not reverting
	
	e.find('span').text(alt_text).addClass('hoverOrange');
	
	newW = content[Number(isOn.substr(5,1))-1][6];
	e.find('div').animate({width: newW}, 500);
	
	e.find('img').css('top','-36px');
	
	newX = newW + 175;
	e.find('img').animate({left: newX}, 500);
	if (isIE()) {e.animate({width: newX-3}, 500);}
}

function closeBlade(id) {
	$('#'+id).find('span').text(orig_text).removeClass('hoverOrange');
	$('#'+id).find('div').animate({width: 0},200);
	if (isIE()) {$('#'+id).animate({width:165},200);}
	$('#'+id).find('img').animate(
		{left: '168px'},
		200,
		function() {
			$(this).prev().css('display','none');
			$(this).css('top','-33px');
			//$(this).parent().hover(function() {hoverOn($(this))}, function () {hoverOff($(this))});
		}
	);
}

function doTrans(id) {
	if (id > 1) {
		//fade out previous
		$('#intro').find('h1').animate({opacity:0},500);
		$('#intro').find('p').animate({opacity:0},500);
		$('#intro').find('#blade').animate({opacity:0},500,function() {
			
			if (content[id-1] != undefined) {
				$('#intro').find('h1').text(content[id-1][0]);
				$('#intro').find('p').html(content[id-1][1]);
				$('#intro').find('#cta').text(content[id-1][2]);
				$('#intro').find('#lbl').text(content[id-1][3]);
				
				$('#intro').find('#blade').attr('href',content[id-1][4]);
				$('#intro').find('h1').removeClass().addClass('tag-'+content[id-1][5]);
				$('#cta').removeClass().addClass('gradient-'+content[id-1][5]+'-36');
				$('#clr').removeClass().addClass('gradient-'+content[id-1][5]+'-36');
				$('#intro').find('img').attr('src','/assets/templates/rce_business/images/tick-'+content[id-1][5]+'.png')
			}
			
			$('#leftnav').find('#blade'+(id-1)).find('img').animate({opacity:1},500);
			$('#leftnav').find('#blade'+(id-1)).animate({opacity:1},500,function() {
				if (id >= 6) {clearTimeout(t);}
			});
			
		});
		
		
	}
	if (id < 6) {
		$('#intro').find('h1').animate({opacity:1},500,function(){
			if (isIE()) {$('#intro').find('h1').css('opacity','');}
			$('#intro').find('p').animate({opacity:1},500,function(){
				if (isIE()) {$('#intro').find('p').css('opacity','');}
				$('#intro').find('#blade').animate({opacity:1},500,function(){
					intro_count++;
					clearTimeout(t);
					t=setTimeout("doTrans(intro_count)",delay_interval);
				})
			})
		});
	} else {tq = setTimeout("fadeQuotes()",2000);}
}

function fadeQuotes() {
	var numQuotes = 7;
	if (quote_count == 0) {
		openBlade($('#blade1'));
		$('#quotes').removeClass('noshow');
		quote_count ++;
		$('#quote'+quote_count).removeClass('noshow');
	$('#quote'+quote_count).animate({opacity:1},2000,function() {tq = setTimeout("fadeQuotes()",2000);});
	} else {
		
		$('#quote'+quote_count).removeClass('noshow');
		$('#quote'+quote_count).animate({opacity:1},2000);
		qprev = (quote_count == 1) ? numQuotes : quote_count-1;
		$('#quote'+qprev).animate({opacity:0},2000,function() {
			$(this).addClass('noshow');
			clearTimeout(tq);
			tq = setTimeout("fadeQuotes()",2000);
		});
	}
	quote_count = (quote_count < numQuotes) ? quote_count+1 : 1;
}



