// JavaScript Document
// Author: spidermanit84@gmail.com

jQuery(document).ready(function() {
    jQuery('.esd-jc').jcarousel();
	
	// LIGHTNBOX
	$('.detail-image a').lightBox({
		imageBtnClose: 'libs/lb/images/lightbox-btn-close.gif'
	});
	
	// Chức năng remove san pham trong album.
	$('.promoted span').click(function(e){
		e.stopImmediatePropagation();
		var sp = $(this).attr("sp");
		var al = $(this).attr("al");
		$.post("modules/album/album_ajax.php", {sp: sp, al: al}, 
			function(data){
				if(data == 1){
					window.location.reload(true);
				}
			}
		);
	});
	
	// show create album trong "Album cua ban"
	$('div.box2 div.tools').click(function(){
		var el = $('div.content-div div.createnewalbum');
		if( el.is(":hidden") )
			el.slideDown();
		else
			el.slideUp();
	});
	
	// hien thi phan tro giup
	$('a[name=trogiup]').click(function(e) {
		e.preventDefault();
		var el = $(this).attr('href');
		if(el) esd.showMaskContent(el);
	});
	
	// VIEW MAP
	$('#viewmap').click(function(e) {
		e.preventDefault();
		if(!$.browser.msie){
			var el = $(this).attr('name');
			if(el) esd.showMaskContent(el);
		}else{
			window.open('theme/default/images/map.jpg', 'help');
		}
		
	});
});

// COMMOND
function ESD(){
	// Tao mot layour covert document	
	this.showMaskContent = function(content){
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#mask').fadeIn(1000);
		$('#mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		//Set the popup window to center
		$(content).css('top',  winH/2-$(content).height()/2);
		$(content).css('left', winW/2-$(content).width()/2);
		
		//transition effect
		$(content).fadeIn(2000);
		
		$('#mask, .window .close').click(function () {
			$('#mask, .window').fadeOut(1000);
		});
	}
}

var esd = new ESD();
