var coinResizeTimer;
function coinPosition() {
	wp = $('#page').width();
	whwr = $('div.bhw-R').width();
	wrez = (whwr-wp/2);
	if(wrez <= 100) {
		$('#coin').width(wrez);
	}
	else {
		$('#coin').width(100);
	}
	if(wp <= 1001) {
		$('#coin').width(0);
	}

};
$(document).ready(function(){

	coinPosition();
	$(window).resize(function() {
		clearTimeout(coinResizeTimer);
		coinResizeTimer = setTimeout( coinPosition, 20);
		coinPosition();
	});	
	
	$('input.iVal').focus( function (){
		if ( $(this).val() == $(this).attr('title') ) $(this).val('').css({color: '#252c2c'}); 	
	});
	$('input.iVal').blur( function (){
		if ( $(this).val() == '' ) $(this).val( $(this).attr('title') ).css({color: '#a4a8a8'}); 	
	});
	
	$('#tHover td').live('mouseover',function(){
		$(this).parents('#tHover tr').addClass('greyRow');
	}).live('mouseout',function(){
		$('#tHover tr.greyRow').removeClass('greyRow');
	});
	
});



function showPopup(index) {
	
	switch (index) {
		case "city":
			popup = $('#popCity');
			break;
		case "vote":
			popup = $('#popVote');
			break;
		case "call2bank":
			popup = $('#popCall2Bank');
			break;
		case "popMessage":
			popup = $('#popMessage');
			break;
        case "popMessage2":
            popup = $('#popMessage2');
            break;
		case "popBankomat":
			popup = $('#popBankomat');
			break;
		case "popCalc":
			popup = $('#popCalc');
			break;
        case "buyHZ":
            popup = $('#buyHZ');
            break;
			
			
	}
	
	blind = $('<div class="blind"></div>');
	pageHeight = $('#wrapper').height();/*(document.documentElement.offsetHeight > document.body.clientHeight) ? document.documentElement.offsetHeight : document.body.clientHeight;*/
	blind.height(pageHeight).click(function(){
		closePopup(popup,blind);
		return false;
	}).appendTo('#wrapper');
		
	setCenter(popup);
	blind.show();
	popup.show();
	$('div.content select').css({visibility: 'hidden'});

	popup.find('.popClose').click(function(){
	closePopup(popup,blind);
	return false;
	});
}
	
function setCenter(item) {
	windowHeight = document.documentElement.clientHeight;
	currentOffset = document.documentElement.scrollTop || document.body.scrollTop;
	
	currentOffset = currentOffset + parseInt((windowHeight - $(item).height()) / 2);
	pLeft = (document.body.clientWidth - $(item).width()) / 2;

	if (currentOffset < 20) { $(item).css({top: 20, left: pLeft}).fadeIn(); }
	else { $(item).css({top: currentOffset, left: pLeft}).fadeIn(); }
	
	return false;
}
function closePopup(popup,blind){
	popup.hide();
	blind.remove();
	$('div.content select').css({visibility: 'visible'});
}

