/*
 * Window class
 * By Pinocio (http://www.pinocio.org)
 * JWin is built on top of the very light weight jquery library.
 * 
 *
 * Created 23.10.2008 by Andrey Rindug (aka eXplozive)
 */


function WIN_Open(win_src, win_w, win_h){

	
	var spacerPuth = templatesRoot+'_i/z.gif';
	var closeImgPuth = templatesRoot+'_i/close.gif';

	//alert(jQuery.browser.version);
	if(jQuery.browser.version == "6.0"){
		var inWidth = clientCoords().w;
	}else{
		var inWidth = $(document).width();
	}
	if($.browser.opera){
		var inWidth = clientCoords().w;
	}

	//Create a body background
	$('body').append('<div id="WIN_bg"></div>');
	$('body').css({
		padding: '0px',
		margin: '0px'
	});
	
	
	//Customize background visuals
	$('#WIN_bg').css({
		backgroundColor: '#000',
		width: inWidth,
		height: clientCoords().h,
		position: 'absolute',
		top: '0px',
		left: '0px',
		zIndex: '1000',
		opacity: 0
	});
	
	$('#WIN_bg').click(function(){
	
		WIN_close();
	
	});
	

	
	//Show the background
	$('#WIN_bg').animate({
		opacity: 0.7
	}, 500 );

	//Create the window width iframe iframe
	
	$('body').append('<table id="WIN_tab" border="0" cellpadding="0" cellspacing="0"><tr><td class="tl"><img src="'+spacerPuth+'" /></td><td class="tc"><img src="'+spacerPuth+'" /></td><td class="tr"><img src="'+closeImgPuth+'" onclick="WIN_close()" style="cursor:pointer;" /></td></tr><tr><td class="cl"><img src="'+spacerPuth+'" /></td><td class="cc" style="width:'+win_w+'px; height:'+win_h+'px;"><iframe src="'+win_src+'" id="WIN_frame" frameborder="0" border="0" ></iframe></td><td class="cr"><img src="'+spacerPuth+'" /></td></tr><tr><td class="bl"><img src="'+spacerPuth+'" /></td><td class="bc"><img src="'+spacerPuth+'" /></td><td class="br"><img src="'+spacerPuth+'" /></td></tr></table>');
	
	$('#WIN_tab').css({
		zIndex: 1021,
		opacity: 0
	});
	//Show the table
	$('#WIN_tab').animate({
		opacity: 1
	}, 500 );

	
	$('#WIN_frame').css({
		width: win_w,
		height: win_h,
		backgroundColor: '#FFFFFF'
	});
	//Positioning the iframe
	WIN_positioning(win_h, win_w, inWidth);

}


function WIN_positioning(win_h, win_w, inWidth){

	if($.browser.opera){
		leftIndex = inWidth/2-win_w/2-22;
	} else {
		leftIndex = $(document).width()/2-win_w/2-22;
	}

	$('#WIN_tab').css({
		position: 'absolute',
		top: $(document).scrollTop()+(clientCoords().h/2-win_h/2)-22,
		left: leftIndex,
		zIndex: 1021
	});
	
	
	$('#WIN_tab').fadeIn('slow');
	
	$('#WIN_bg').css({
		top: $(document).scrollTop()
	});
	
	setTimeout("WIN_positioning("+win_h+", "+win_w+")", 10);

}


function clientCoords(){
    if(window.innerHeight || window.innerWidth){
        return {
			w:window.innerWidth, 
			h:window.innerHeight
		}
    }
    return {
        w:document.documentElement.clientWidth,
        h:document.documentElement.clientHeight
    }
}


function WIN_close(){
	
	$('#WIN_bg').animate({
		opacity: 0
	}, 500 );
	//Show the table
	$('#WIN_tab').animate({
		opacity: 0
	}, 500, WIN_destroy );

}

function WIN_destroy(){
	
	$('#WIN_bg').remove();
	$('#WIN_tab').remove();
	
}
