// JavaScript Document

jQuery.fn.belightbox = function(settings) {
	settings = jQuery.extend({
	popupid:"modalpopupdiv",
	cancelclass:"cancelpop"
	}, settings);
	return this.each(function(){

		var container = jQuery(this);
		var popup= $(container.attr('href'));
		popup.hide();
		var documentheight=$(document).height();
		var windowheight=$(window).height();
		var docwidth=$(document).width();
		var popupheight=popup.height();
		var popupwidth=popup.width();
		var setleft=(docwidth-popupwidth)/2;
		
		container.click(function(){

			var setpoptop=parseInt(windowheight)+parseInt($(window).scrollTop());
			setpoptop=(setpoptop-popupheight)/2;
			if(popup.not('visible'))
			{
			$('#modallayer').width(docwidth);
			$('#modallayer').height(documentheight);
			$('#modallayer').css('opacity',0.7)
			$('#modallayer').show();
			popup.css('left',setleft+'px');
			popup.css('top',setpoptop+'px');
			popup.show() 
			}
			return false
		})

		popup.find('.'+settings.cancelclass).click(function(){
			$('#modallayer').fadeOut();
			popup.hide() ;
			return false;
		})

		$('#modallayer').click(function(){
			$('#modallayer').fadeOut();
			popup.hide()
		})
	});
}

jQuery.fn.show_modal = function() {
	$('#modallayer2').click(function(){
		$('#modallayer2').fadeOut();
		$('#modalpopupsnlogin').hide();
	});
	$(this).find('.cancelpop').click(function(){
		$('#modallayer2').fadeOut();
		$('#modalpopupsnlogin').hide();
		return false;
	});
	var setpoptop=parseInt( $(window).height() )+parseInt($(window).scrollTop());
	setpoptop=(setpoptop-$(this).height())/2;
	
	var setleft=( $(document).width()-$(this).width() )/2;
	if( $(this).not('visible') ){
		
		$('.boxRound').corner({
			tl: {radius: 10},
			tr: {radius: 10},
			bl: {radius: 10},
			br: {radius: 10}
		});
		
		$('#modallayer2').width($(document).width());
		$('#modallayer2').height($(document).height());
		$('#modallayer2').css('opacity',0.7)
		$('#modallayer2').show();
		$(this).css('left',setleft+'px');
		$(this).css('top',setpoptop+'px');
		$(this).show(); 
	}
	return false
}

