
//SETTING UP OUR RETAILERS POPUP  
//0 means disabled; 1 means enabled;  
var popupStatus = 0; 

//loading popup with jQuery magic!  
function loadPopup(idToLoad)
{
	//loads popup only if it is disabled  
	if(popupStatus==0)
	{
		$("#backgroundPopup").css({  
			"opacity": "0.7"  
		});  
		$("#backgroundPopup").fadeIn("slow");  
		$(".content").find("#retailers-"+idToLoad+"-content").fadeIn("slow");  
		popupStatus = 1;  
	}  
}

//disabling popup with jQuery magic!  
function disablePopup()
{
	//disables popup only if it is enabled  
	if(popupStatus==1)
	{
		$("#backgroundPopup").fadeOut("slow");  
		$(".popupRetailers").fadeOut("slow");  
		popupStatus = 0;  
	}  
}

$(document).ready(function(){	
	$("#slider").easySlider();
	
	//LOADING POPUP  
	//Click the button event!  
	$(".openPopup").click(function(){
		//load popup 
		
		// each button div MUST have a "xx-button" and the target div must have an id "xx"
		var idToLoad = $(this).attr("id").split('-');

		loadPopup(idToLoad[1]);  
	});

	//CLOSING POPUP  
	//Click the x event!  
	$(".popupRetailersClose").click(function(){  
		disablePopup();  
	});  
	
	//Click out event!  
	$("#backgroundPopup").click(function(){  
		disablePopup();  
	});  
	
	//Press Escape event!  
	$(document).keypress(function(e)
	{  
		if(e.keyCode==27 && popupStatus==1){  
			disablePopup();  
		}  
	}); 
	
});

function changeLevel(id)
{
	document.getElementById("left_level").innerHTML = "<img src=\"pictures/menu_level_"+id+".png\" alt=\"Level\">";
}

// Slide effect on news
function news_slideup(number)
{
	for (i=1; i<=number; i++)
	{
		$("#vertical_slide"+i+"").slideUp("fast");
	}
}

function news_slide(number)
{
	$("#vertical_slide"+number+"").slideToggle("slow");
}

// Slide effect on credit card CVV
function cvv_slideup()
{
	$("#purchasing_payment_cvv").slideUp("fast");
}

function cvv_slide()
{
	$("#purchasing_payment_cvv").slideToggle("slow");
}

// load the images used by the clock (the images are are digits from 0 to 9 with the same dimension for each image)
// make sure browsers is capable to run this script by checking that "document.images" object exists
// if you have a different path(s) or filename(s), substitute the filenames/path with the correct ones
// if the path is on the current directory, put nothing between the quotes
var imgPath="pictures/"

if (document.images)
{
	digitImages=new Array
	for (i=0; i<10; i++)
	{
		digitImages[i]=new Image();
        digitImages[i].src=""+imgPath+"timer_"+i+".png";
    }
}

function tickClock()
{
    // this tells the browser to call the "tickClock()" function every 1 second
    setTimeout("tickClock()", 1000);

    // make sure all the digit images are loaded
    if (document.images)
    {
        for (i=0; i<10; i++)
        {
            if (!digitImages[i].complete)
                return;
        }
    }                        

    var thisTime = new Date()
	year = thisTime.getFullYear()
	month = thisTime.getMonth()+1
	day = thisTime.getDate()
    hours = thisTime.getHours()
    minutes = thisTime.getMinutes()
    seconds = thisTime.getSeconds()

    // convert the digit to string
    // make sure there're at least 2 digits
	
	yearString="0"+year+""
	monthString="0"+month+""
    dayString="0"+day+""
    hourString="0"+hours+""
    minuteString="0"+minutes+""
    secondString="0"+seconds+""
	
    // format the year
    year1=parseInt(yearString.charAt(yearString.length-1))
    year2=parseInt(yearString.charAt(yearString.length-2))
    year3=parseInt(yearString.charAt(yearString.length-3))
    year4=parseInt(yearString.charAt(yearString.length-4))
	
    // format the month
    month1=parseInt(monthString.charAt(monthString.length-1))
    month2=parseInt(monthString.charAt(monthString.length-2))
	
    // format the day
    day1=parseInt(dayString.charAt(dayString.length-1))
    day2=parseInt(dayString.charAt(dayString.length-2))
	
    // format the hour
    hour1=parseInt(hourString.charAt(hourString.length-1))
    hour2=parseInt(hourString.charAt(hourString.length-2))

    // format the minute
    minute1=parseInt(minuteString.charAt(minuteString.length-1))
    minute2=parseInt(minuteString.charAt(minuteString.length-2))

    // format the seconds
    second1=parseInt(secondString.charAt(secondString.length-1))
    second2=parseInt(secondString.charAt(secondString.length-2))

    if (document.images)
    {
        // update the images
		document.getElementById('hour1Image').src=digitImages[hour2].src;
		document.getElementById('hour2Image').src=digitImages[hour1].src;
		document.getElementById('minute1Image').src=digitImages[minute2].src;
		document.getElementById('minute2Image').src=digitImages[minute1].src;
		document.getElementById('second1Image').src=digitImages[second2].src;
		document.getElementById('second2Image').src=digitImages[second1].src;
		document.getElementById('day1Image').src=digitImages[day2].src;
		document.getElementById('day2Image').src=digitImages[day1].src;
		document.getElementById('month1Image').src=digitImages[month2].src;
		document.getElementById('month2Image').src=digitImages[month1].src;
		document.getElementById('year1Image').src=digitImages[year4].src;
		document.getElementById('year2Image').src=digitImages[year3].src;
		document.getElementById('year3Image').src=digitImages[year2].src;
		document.getElementById('year4Image').src=digitImages[year1].src;
	}
}
        
//end of script -->
