jQuery(function() {
	//Create a lightbox content container
	//Target the lightbox-container-content div to hold your content.
	jQuery('body').append('<div id="lightbox-container" class="jqmDialog">' +
		'<div class="jqDrag popup-drag-outer">' +
			'<div class="popup-drag-inner">' +
				'<a href="#" class="jqmClose popup-closer">close</a>' +
			'</div>' + 
		'</div>' +
		'<div id="lightbox-container-content" class="clearfix popup-content"></div>' +
		'<div class="popup-bottom-outer">' +
			'<div class="popup-bottom-inner">&nbsp;</div>' +
		'</div>' +
	'</div>');
	jQuery('#lightbox-container').jqm({modal: true,
		onShow: function(hash) {
			//PNG-24 for IE6  supersleight required for buttons in popup. 
			//Does not cascade into popup without this.
			jQuery(hash.w).find('.btn, button').supersleight();
			jQuery('.PNG24').supersleight({backgrounds: false});
			jQuery('#tab-item-specifics').simplyTabs();
			jQuery(hash.w).show();
			// Vertically align phone features controls, if they're there, within its parent.
			// We must do this AFTER show(), as the heights haven't been calculated by the browser yet.
			jQuery('#item-features-wrapper').vAlign();
		},
		onHide: function(hash) {
			
			hash.w.fadeOut('1000',function(){ 
				
				hash.c.trigger = null;
				hash.c.ajax = null;
				hash.c.target = null;
				
				var classes = jQuery(hash.w).attr('class');
				var resetclasses = '';
				var classesarray = classes.split(' ');
				jQuery.each(classesarray,
						function( idx, val ) {
							if (val.indexOf('jqm') == 0) {
								var sp = '';
								if (idx > 0) {sp = ' ' + val;}
								else {sp = val;}
								resetclasses += sp;
							}
						}
				);
				jQuery(hash.w).attr( {'class' : resetclasses} );
				
				hash.o.remove();
			
			});
		}
	}).draggable({ handle: '.jqDrag', opacity: 0.5 });
	
	//css class for default popup implementation
	//will use the anchor's href to popup content
	jQuery('a.lightbox-enable').click(
		function(event) {
			event.preventDefault();
			var url = this.href;
			jQuery.get(
				url,
				function(data) {
					jQuery('#lightbox-container-content').html(data);
					jQuery('#lightbox-container').jqmShow();
				}
			);
		}
	);


	jQuery('a.international-text-popup').click(
		function(event) {
			event.preventDefault();
			var url = this.href;
			jQuery.get(
				url,
				function(data) {
					jQuery('#lightbox-container-content').html(data);
					jQuery('#lightbox-container').addClass('popup-international-text-countries');					
					jQuery('#lightbox-container').jqmShow();
				}
			);
		}
	);	


	jQuery('a.policy-popup').click(
		function(event) {
			event.preventDefault();
			var url = this.href;
			jQuery.get(
				url,
				function(data) {
					jQuery('#lightbox-container-content').html(data);
					jQuery('#lightbox-container').addClass('policy-popup');
					jQuery('#lightbox-container').jqmShow();
				}
			);
		}
	);		
	
});

function showPopup(divId, width) {
    jQuery('#lightbox-container').width(width);
    if(width < 300 ) {
        jQuery('#lightbox-container').css("padding-left", (width/2));
    }
    jQuery('#lightbox-container-content').html( jQuery('#'+ divId).html() );
    jQuery('#lightbox-container').jqmShow(); 
    //event.preventDefault();
}

function hidePopup() {
	jQuery('#lightbox-container').jqmHide(); 
}