var origWidth =-1;
var origHeight = -1;

$(document).ready(function() {
    $('#viewdetails').click(function() {
        _buildLightbox($('#data').outerWidth(),$('#data').outerHeight());
        return false;
        alert('called');
    });
	function _buildLightbox(setW, setH) {
		var setWidth = setW;
		var setHeight = setH;
		var setContentWidth = setWidth - 40;
		var setContentHeight = setHeight - 40;
		if(origWidth == -1){
			origWidth = setWidth;
			origHeight = setHeight;
		}
		// build this puppy
		// build overlay
		//$('html, body').css('overflow', 'hidden');
		$('body').append('<div id="lightboxOverlay"></div>');
		// build lightbox
		$('body').append('<div id="lightboxContentWrap"><div id="lightbox_nw">&nbsp;</div><div id="lightbox_n">&nbsp;</div><div id="lightbox_ne">&nbsp;</div><div id="lightbox_w">&nbsp;</div><div id="lightbox_content"><a class="close" href="javascript:_destroyLightbox()">Close</a></div><div id="lightbox_e">&nbsp;</div><div id="lightbox_sw">&nbsp;</div><div id="lightbox_s">&nbsp;</div><div id="lightbox_se">&nbsp;</div></div>');
		// append the data
		$('#lightbox_content').append($('#data').html());
		Cufon.now(); 
			
		// style this puppy			 
		$('#lightboxContentWrap').css('width', origWidth+'px').css('height', origHeight+'px');

		
		// define the inner parts of the lightbox
		//$('#contentShell, #lightbox_content, .lightbox').css('width', setContentWidth+'px').css('height', setContentHeight+'px');
		$('#contentShell, #lightbox_content, .lightbox').css('width', origWidth - 40+'px').css('height', origHeight - 40+'px');
		// this grows the height of left and right shadow
		//$('#lightbox_n, #lightbox_s ').css('width', setContentWidth+'px');
		$('#lightbox_n, #lightbox_s ').css('width', origWidth - 40+'px');
		// this grows the height of left and right shadow
		//$('#lightbox_w, #lightbox_e ').css('height', setContentHeight+'px');
		$('#lightbox_w, #lightbox_e ').css('height', origHeight - 40+'px');
		// positions lighbox
		//$('#lightboxContentWrap').css('top', ($('body').height()/2)-(setHeight)/2).css('left', ($('body').width()/2)-(setWidth/2));	
	 	$('#lightboxContentWrap').css('top', ($('body').height()/2)-(origHeight)/2).css('left', ($('body').width()/2)-(origWidth/2));

	 	$('#lightbox_nw').supersleight();
	 	$('#lightbox_n').supersleight();
	 	$('#lightbox_ne').supersleight();
	 	$('#lightbox_w').supersleight();
	 	$('#lightbox_e').supersleight();
	 	$('#lightbox_sw').supersleight();
	 	$('#lightbox_s').supersleight();
	 	$('#lightbox_se').supersleight();
			 
	    $('#lightboxOverlay').click(function() {
		    _destroyLightbox()
	    });
	
	/*$('#lightboxContentWrap').click(function() {
		_destroyLightbox()
	});*/
	$('div#lightbox_content a.close').click(function() {
	    _destroyLightbox()
	});

	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	
	if ((version <= 6) && (document.body.filters)) 
	{
		pngfix(); // if IE apply png fix
	}
	Cufon.now(); 
			return false;
	}
	
	function _destroyLightbox() {
		//$('html, body').css('overflow', 'visible');
		$('#lightboxOverlay').remove();
		$('#lightboxContentWrap').remove();
	};	
	

});
// ------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------


$(window).resize(function(){
		var winH = ($('body').height());
		var rcolW = ($('#rightColLight').width());
		var lcolW = ($('#leftCol').width());
		$('#leftCol').css('height',winH);
		$('#rightColLight').css('height',winH).css('width',$('body').width()-lcolW);
		$('.flashShell').css('height',winH-39).css('width',$('body').width()-(lcolW+60));
	 	$('#lightboxContentWrap').css('top', ($('body').height()/2)-($('#lightboxContentWrap').height()/2)).css('left', ($('body').width()/2)-($('#lightboxContentWrap').width()/2));					
		Cufon.now(); 
});