/*******************************
POPUP INFORMATION WINDOWS

@NEXUM BOGAZICI
@AUTH: Ugur KORFALI

*******************************/
		
// Get DOM elements
var infoPopup;
var infoPopupOverlay;
var infoOverlayIframe;
var infoPopupClose;
var btnClose;
var btnChangeAnyway;

// Displays information popup on screen as centered 
function showInfoPopup(url,popupWindow){
	
		var overlayHtml = '<div class="infoPopupOverlay"><!--[if lte IE 6]><iframe src="javascript:false;document.write(\'\');" class="infoOverlayIframe"></iframe><![endif]--></div>';

		
		
		infoPopup = jQuery(popupWindow);
		jQuery(overlayHtml).insertBefore(infoPopup);
		
		btnChangeAnyway = jQuery('div.infoPopup a.changeAnywayButton');
		btnChangeAnyway.attr('href', url);
		
		infoPopupOverlay = jQuery('div.infoPopupOverlay');
		infoOverlayIframe = jQuery("iframe.infoOverlayIframe");
				
		// Calculates total hight and width of the current page.
		var overlayHeight = jQuery(document).height();
		var overlayWidth = jQuery("body").width();
		
		var popupTopMargin;
		
		// Prapares overlay div and binds close action to it's click event.
		infoPopupOverlay
		.css('opacity' , 0.5)
		.height(overlayHeight)
		.width(overlayWidth)
		.bind('click', function(){closeInfoPopup();});
		
		// Aligns the information popup to center vertically
		popupTopMargin = parseInt(jQuery(window).height()) / 2 - parseInt(infoPopup.height()) / 2;
		popupTopMargin += parseInt(jQuery(window).scrollTop());
		// Displays overlay div
		infoPopupOverlay.css('visibility','visible');
		
		// To prevent selectbox z-index bug, displays empty iframe element for IE6 and previous versions
		if (jQuery.browser.msie && parseInt(jQuery.browser.version) <= 6) {
			infoOverlayIframe.css({
								  'opacity' : 0,
								  'display' : 'block' 					  
								  });
		}
		
		// Displays information popup
		infoPopup.css({
					  'margin-top' : popupTopMargin,
					  'visibility' : 'visible'
					  });
}

// Closes information popup
function closeInfoPopup(){
		infoPopup.css('visibility', 'hidden');
		infoPopupOverlay.remove();
		infoOverlayIframe.remove();
}

jQuery(document).ready(function(){
						   
infoPopupClose = jQuery('div.infoPopup a.popupCloseButton');
btnClose = jQuery('div.infoPopup a.contentButtonClose');

// Bind close action to Close link
btnClose.bind('click', function(e){
	e.preventDefault();
	closeInfoPopup();
});

infoPopupClose.bind('click', function(e){
	e.preventDefault();
	closeInfoPopup();
});

// Binds showInfoPopup action to click event for all a elements in country selection box
jQuery('ul.wepCountriesContainer a').bind('click', function(e){
	
	if(jQuery('div.infoPopup.changeCountryPopup').length > 0)
	{
		
		e.preventDefault();
		var url = jQuery(this).attr('href');
		showInfoPopup(url, 'div.infoPopup.changeCountryPopup');
	}
	else
	{
		
		return true;
	}
	
	

	
});
	
	
});
		
		
		
		
	
