var main_links, index, countdown_img, contact_links, src, later;
$(document).ready(function() {
    $('.mtl, .mtr').each(function(i) { $(this).attr('href', 'mailto:'+$(this).attr('href')+'@losteidolons.com');});
    
    FLIR.init( { path: './flir/' } );
    FLIR.replace( 'a.mtl' , new FLIRStyle({ cFont:'type' }) );
    FLIR.replace( 'a.mtr' , new FLIRStyle({ cFont:'type' }) );
    
    countdown_img = $('img.countdown');

    contact_links = $('.mtl, .mtr');
    contact_links.each(function(i) {$(this).fadeTo(1, 0);});
    
    main_links = $('.logo, .main_link, .contact_link');
    main_links.each(function(i) {$(this).fadeTo(1, 0);});
    index = -1;
    start_time();
//    get_time();
    fadeIn();
});
 
function fadeIn()
{
    index += 1;
    if( index >= main_links.length )
        return;
    main_links.eq(index).fadeTo(500, 1, fadeIn);
}

for(i=0;i<10;i++)
{
    eval('s'+i+' = new Image(); s'+i+'.src = "images/symbols/'+i+'.jpg";');
    eval('c'+i+' = new Image(); c'+i+'.src = "images/numbers/'+i+'.jpg";');
}
 
lastTime = new Array();	
thisTime = new Array();

function getImage() {
    var rand = Math.floor(Math.random()*10);
    if( rand > 5 ) { return "c"; }
    else { return "s"; } 
}

function start_time() {
	//DDD:HH:MM:SS
	//012 34 56 78

	//ENTER BELOW THE DATE YOU WISH TO COUNTDOWN TO
	later = new Date("Sep 24 2010 22:00:00");
	now = new Date();
	
	if (later > now) {
	    get_time();
	} else {
	    rand_time();
	}
}

function get_time() {
	now = new Date();

    daysRound = Math.floor((later - now) / 1000 / 60 / 60 / 24);
	hoursRound = Math.floor((later - now) / 3600000 - (24 * daysRound));
	minutesRound = Math.floor((later - now) / 60000 - (1440 * daysRound) - (60 * hoursRound));
	secondsRound = Math.floor((later - now) / 1000 - (86400 * daysRound) - (3600 * hoursRound) - (60 * minutesRound));

	// days
	thisTime[0] = Math.floor(daysRound/100);
	thisTime[1] = Math.floor((daysRound/10)%10);
	thisTime[2] = Math.floor(daysRound%10);
	// hours
	thisTime[3] = Math.floor(hoursRound/10);
	thisTime[4] = hoursRound%10;
	// minutes
	thisTime[5] = Math.floor(minutesRound/10);
	thisTime[6] = (minutesRound%10);
	// seconds
	thisTime[7] = Math.floor(secondsRound/10);
	thisTime[8] = (secondsRound%10);
	
	for(var i=0;i<9;i++)
	{
	    if( lastTime[i] != thisTime[i] ) {
		    lastTime[i] = thisTime[i];
		    countdown_img.eq(i).attr('src', eval(getImage()+thisTime[i]+'.src'));
	    }
	}
 		
	newtime = window.setTimeout("get_time();", 1000);
}

function rand_time() {
	now = new Date();

    d1 = Math.floor(Math.random()*9);
    d2 = Math.floor(Math.random()*9);
    while (d1 == d2) {
        d2 = Math.floor(Math.random()*9);
    }
    
    thisTime[d1] = Math.floor(Math.random()*9);
    thisTime[d2] = Math.floor(Math.random()*9);
	
    if( lastTime[d1] != thisTime[d1] ) {
	    lastTime[d1] = thisTime[d1];
	    countdown_img.eq(d1).attr('src', eval(getImage()+thisTime[d1]+'.src'));
    }
    if( lastTime[d2] != thisTime[d2] ) {
	    lastTime[d2] = thisTime[d2];
	    countdown_img.eq(d2).attr('src', eval(getImage()+thisTime[d2]+'.src'));
    }
 		
	newtime = window.setTimeout("rand_time();", 1000);
}

function contactInfo()
{
    if( contact_links.eq(0).css('display') == 'block' )
    {
        contact_links.each(function(i) {$(this).fadeTo(1000, 0, function(i) {$(this).css({'display':'none'});});});
    }
    else
    {
        contact_links.each(function(i) {$(this).css({'display':'block'});});
        contact_links.each(function(i) {$(this).fadeTo(1000, 1);});
    }
}
