/* Add Popup to Shipping Links */
	Event.observe(window, 'load', function()  {
																	$$('a').each(function(elem, i)  {
																										if (Element.hasClassName(elem.parentNode, 'tax-details'))  {
																											popup = new OneStepCheckout_Popup('shipping-rate-popup',elem , 'div#shipping-rate-popup p.close a');
																											//elem.observe('click', function(e)  { 
																											//					e.stop(); 
																											//					
																											//});
																										};
																									});
																});

/* Terms and conditions Popup Javascript from OneStepCheckout */

function OneStepCheckout_Popup(popup_id, link_id, close_link_search)
{
	this.popup_id = popup_id;
	this.popup = $(popup_id);
	this.link_id = link_id;
	this.link = $(link_id);
    this.close_link_search = close_link_search;
	
	var onestepcheckout_popup = this;
	
	if(this.link != null)	{
		this.link.observe('click', function(e)	{

			e.preventDefault();
			onestepcheckout_popup.show();
		});
	}
	
	var close_link = $$(this.close_link_search);
	if(close_link.length > 0)	{
		close_link[0].observe('click', function(e)	{
			e.preventDefault();
			onestepcheckout_popup.hide();
		});
	}
    
    this.overlay = $('shipping-rate_popup_overlay');
    
    this.overlay.observe('click', function(e)   {
         onestepcheckout_popup.hide();
    });
    
}

OneStepCheckout_Popup.prototype.show_overlay = function()
{
    this.overlay.show();
    
    var dimensions = document.viewport.getDimensions();
				var offset = document.viewport.getScrollOffsets();
		
				var dimensions_new = {
       	height: (dimensions.height + offset.top) + 'px',
								width: (dimensions.width) + 'px'
    }
		
    this.overlay.setStyle(dimensions_new);
		
	/* IE Hack */
	var IE6 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf('MSIE')+5)) == 6;
		
	if(IE6)	{
		$$('select').invoke('hide');
	}
		
}

OneStepCheckout_Popup.prototype.show = function()
{
 			this.show_overlay();
				this.popup.show();
				this.center();
}

OneStepCheckout_Popup.prototype.hide = function()
{
    this.overlay.hide();
	
	/* IE Hack */
	var IE6 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf('MSIE')+5)) == 6;
		
	if(IE6)	{
		$$('select').invoke('show');
	}
	
	this.popup.hide();
}

OneStepCheckout_Popup.prototype.center = function()
{
	var dimensions = document.viewport.getDimensions();
	var popup_width = this.popup.getWidth();
	var popup_height = this.popup.getHeight();
	var offset = document.viewport.getScrollOffsets();

	var width = dimensions.width;
	var left = (width / 2) - (popup_width / 2);
	
	var height = dimensions.height;
	var top = (height / 2) - (popup_height / 2) ;//+ offset.top;
	
	this.popup.setStyle({
		top: top + 'px',
		left: left + 'px'
	});
}
