$(document).ready(function() {

	// tasty box loader do not modify
	$(window).resize(function(){
		if(popup == 1){
			if(screenHeight != $(window).height() || screenWidth != $(window).width()){
				screenSize();
				popupPos();
			}
		}
		if(saveOn = 1){
			$('#saveBar').animate({
				'width' : '100%'
			}, 5);
		}
	});
	
	
	
	$('.yes').live('click', function(){
		showWaiting('Processing...');
		func = $(this).attr('id');
		window[func]();
	}).live('mouseover', function(){
		$(this).css('font-weight', 'bold');
	}).live('mouseout', function(){
		$(this).css('font-weight', 'normal');
	});
	
	$('.no').live('click', function(){
		if($(this).attr('id') != ''){
			showWaiting('Processing...');
			func = $(this).attr('id');
			window[func]();
		}else{
			hidePopup();
		}
	}).live('mouseover', function(){
		$(this).css('font-weight', 'bold');
	}).live('mouseout', function(){
		$(this).css('font-weight', 'normal');
	});
	
	$('#screen').hide();
	$('#popup').hide().addClass('popup');
	
	screenHeight = $('body').height();
	screenWidth = $('body').width();
	
});
	
var popup = 0;

function hidePopup(){
	
	$('#popup').removeClass().addClass('popup');
	popup = 0;
	clearTimeout(delay);
	$('#popup').hide();
	$('#screen').hide(1);
	
}

function showPopup(speed, html, opacity, color){

	$('#popup').removeClass().addClass('popup');
	hidePopup();
	popup = 1;
	showScreen(opacity, color);
	if(html){
		$('#popup').html(html);
	}
	popupPos();
	delay = setTimeout(function(){hidePopup()},5000);
	$('#popup').show(speed)

}


function showScreen(opacity, color){
	if(opacity < 1){
		$('#screen').css('opacity', opacity);
	}
	if(color != 0){
		$('#screen').css('background-color', ''+color+'');
	}else{
		$('#screen').css('background-color', 'transparent');
	}
	screenSize();
	$('#screen').show(1);
}

function screenSize(){
	
	$('#screen').height($(document).height()).width($(document).width());
	
}

function popupPos(){
	
	var halfHeight = $(window).height()/2;
	var halfWidth = $(window).width()/2;
	var	top = Math.round(halfHeight-($('#popup').height()/2)-100);
	var	left = Math.round(halfWidth-($('#popup').width()/2)); 
	
	var scrollT = $(document).scrollTop();
	var scrollL = $(document).scrollLeft();
	top = top+scrollT;
	left = left+scrollL;
	
	if(top < 0){
		top = 0;
	}
	if(left < 0){
		left = 0;
	}
	
	$('#popup').animate({
		//'top': top+'px',
		'left': left+'px'
	}, 5);

}

var delay;

function showWaiting(message){

	$('#popup').removeClass().addClass('popup');
	if(message === false || typeof(message) == 'object'){
		message = 'Processing..';
	}
	var html = '<img src="images/ajax-loader.gif"></img><p>'+message+'</p>';
	showPopup('fast', html, 1, 0);
	
}

function showWaitingScr(message){

	$('#popup').removeClass().addClass('popup');
	if(message === false || typeof(message) == 'object'){
		message = 'Processing..';
	}
	var html = '<img src="images/ajax-loader.gif"></img><p>'+message+'</p>';
	showPopup('fast', html, 0.4, '#8C0705');
	
}