// JavaScript Document
$(document).ready(function() {
	
	$('.menu_elem').mouseover(function() {
		$('#menu_current').removeClass('current');
	});
	$('.menu_elem').mouseout(function() {
		$('#menu_current').addClass('current');
	});
	
	stLight.options({publisher:'9db3d588-cfc4-4eaf-95f0-9bd6d7152e8d'});
	
	$().busy("defaults", { img: 'img/jquery/loader.gif' , alt: 'Loading...' } );
	$().busy("preload");
	
	//currColors = ({ top: colorBottom['top'], center: colorBottom['center'], bottom: colorBottom['bottom'] });
	//pulseBackground("010101","010101","000000",100);
	
	/*var holder = document.createElement('div');
	holder.setAttribute('style','position:absolute; top:10px; left: 10px;');
	
	var btn1 = document.createElement('input');
	btn1.setAttribute("type","button");
	btn1.setAttribute("id","btn1");
	btn1.value = "BG1";
	
	var btn2 = document.createElement('input');
	btn2.setAttribute("type","button");
	btn2.setAttribute("id","btn2");
	btn2.value = "BG2";
	
	var btn3 = document.createElement('input');
	btn3.setAttribute("type","button");
	btn3.setAttribute("id","btn3");
	btn3.value = "BG3";
	
	var btn4 = document.createElement('input');
	btn4.setAttribute("type","button");
	btn4.setAttribute("id","btn4");
	btn4.value = "BG4";
	
	holder.appendChild(btn1);
	holder.appendChild(btn2);
	holder.appendChild(btn3);
	holder.appendChild(btn4);
	
	$('body').append(holder);
	
	$('#btn1').click(function() {
		$('body').removeClass();
		$('body').addClass('bg1');
	});
	
	$('#btn2').click(function() {
		$('body').removeClass();
		$('body').addClass('bg2');
	});
	
	$('#btn3').click(function() {
		$('body').removeClass();
		$('body').addClass('bg3');
	});
	
	$('#btn4').click(function() {
		$('body').removeClass();
		$('body').addClass('bg4');
	});
	
	$('body').addClass('bg1');*/
	
});


var colorBottom = { top: "c3c1c1", center: "f6f4f5", bottom: "f4f2f3" };
var colorTop = { top: "f3f1f1", center: "ffffff", bottom: "f4f2f3" };
var currColors = Array();

var colorFadeDirection = 1;

function pulseBackground(top,center,bottom,speed)
{	
	currColors['top'] = ( parseInt(currColors['top'],16) + (colorFadeDirection) * (parseInt(top,16)) ).toString(16);
	currColors['center'] = ( parseInt(currColors['center'],16) + (colorFadeDirection) * (parseInt(center,16)) ).toString(16);
	currColors['bottom'] = ( parseInt(currColors['bottom'],16) + (colorFadeDirection) * (parseInt(bottom,16)) ).toString(16);
	
	currColors['top'] = colorInRange(currColors['top'], colorTop['top'], colorBottom['top']);
	currColors['center'] = colorInRange(currColors['center'], colorTop['center'], colorBottom['center']);
	currColors['bottom'] = colorInRange(currColors['bottom'], colorTop['bottom'], colorBottom['bottom']);
	
	if( ( currColors['top'] == colorBottom['top'] || parseInt(top,16) == 0 ) && 
		( currColors['center'] == colorBottom['center'] || parseInt(center,16) == 0 ) && 
		( currColors['bottom'] == colorBottom['bottom'] || parseInt(bottom,16) == 0 ) )
	{
		colorFadeDirection = 1;
	}
	else if( ( currColors['top'] == colorTop['top'] || parseInt(top,16) == 0 ) && 
		( currColors['center'] == colorTop['center'] || parseInt(center,16) == 0 ) && 
		( currColors['bottom'] == colorTop['bottom'] || parseInt(bottom,16) == 0 ) )
	{
		colorFadeDirection = -1;
	}
	
	$("body").css( "background", "-webkit-linear-gradient(top, #"+currColors['top']+" 0%, #"+currColors['center']+" 44%, #"+currColors['bottom']+" 100%)" );
	
	setTimeout("pulseBackground('"+top+"','"+center+"','"+bottom+"',"+speed+")", speed);
	
}

function colorInRange(value,top,bottom)
{
	if(parseInt(value,16) >= parseInt(top,16))
	{
		return top;
	}
	else if(parseInt(value,16) <= parseInt(bottom,16))
	{
		return bottom;
	}
	else
	{
		return value;
	}
}
