/**
 * SPREE menu initialization
 */
function SPREEInitMenu() {
    //main menu:
	$("ul.dropdown li").hover(function(){

		$(this).addClass("hover");
		$('ul:first',this).css('visibility', 'visible');

	}, function(){

		$(this).removeClass("hover");
		$('ul:first',this).css('visibility', 'hidden');

	});

	$("ul.dropdown li ul li:has(ul)").find("a:first").prepend("<span class='arrow'>&raquo;</span>");
}

/**
 * SPREE login panel initialization
 */
function SPREEInitLoginPanel(login_text_localized) {
	//make a Login button
	$('#javascriptLogin').html('<button>'+login_text_localized+'</button>');
	$('#javascriptLogin button').button();

	//style the login form
	$('#login').addClass('javascriptLoginForm');
	$('#login').addClass('ui-corner-all');

	//alive the button
	$('#javascriptLogin button').click(function()
	{
		$('#login').toggleClass('ui-corner-all')
			.toggleClass('ui-corner-bottom')
			.toggleClass('ui-corner-left');

		$('#javascriptLogin button').toggleClass('ui-corner-all')
			.toggleClass('ui-corner-top')
			.toggleClass('toggled');

		 $('#login').slideToggle(100);
		 $('#frmloginForm-username').focus();
		return false;
	});
}

/**
 * SPREE Header text init
 */
function SPREEInitHeaderText() {
    $('.cont .flying-text').css({
		display: 'block',
		opacity:0,
		left: '0px'
	}); //set all text opacity to 0

	// random positioning
	var pos = (Math.random()*600)+100;
	if((pos + $('.cont .active-text').width()) > 700) pos = 700 - $('.cont .active-text').width();
	if(pos < 0){pos = 200;}

	$('.cont .active-text')
		.css('top', Math.round(Math.random()*100)+'px')
		.css('left', pos+'px')
		.animate(
		{
			opacity:1
		}, 3000); //animate first text
	var inte = setInterval(changeText, 4000); // call changeText function every 5 seconds
}


function changeText()
{
	var $activeText = $('.cont .active-text'); //get current text
	var $nextText = $activeText.next();  //get next text
	$activeText.stop(true, true);
	$nextText.stop(true, true);
	if($activeText.next().length == 0)
	{
		$nextText = $('.cont .flying-text:first'); //if it is last text, loop back to first text
	}

	$activeText.animate({opacity:0}, 1000); //set opacity 0 to animated text
	//$activeText.animate({ left: '0px'}); //set animated text position to default

	//animate next text
	var pos = (Math.random()*600)+100;
	if((pos + $nextText.width()) > 700) pos = pos - $nextText.width();
	if(pos < 0){pos = 200;}

	$nextText.css({opacity: 0, top: Math.round(Math.random()*100)+'px',left: pos+'px'})
		.addClass('active-text')
		.animate({opacity:1}, 3000, function()
			{
				$activeText.removeClass('active-text');
			});
	//$nextText.css({ left: 0});
}

function showAjaxSpinner() {
    $("body").prepend('<div id="overlay"><div id="ajax-spinner-overlay-wrap"><div id="ajax-spinner-overlay"></div></div></div>');
	$("#overlay").css("height", $("body").height()+"px");
	$("#overlay").css("width", $("body").width()+"px");
	$("#overlay").click(function(){$(this).remove()});
}

function hideAjaxSpinner() {
    $('#overlay').remove();
}

function isInt(x) {
		var y=parseInt(x);
		if (isNaN(y)) return false;
		return x==y && x.toString()==y.toString();
	} 

