var Site = {
	init: function() {
	
	},
	subscribe: function(form) {
		$('#newsletter_indicator').show();
		$.getJSON(form.action, {fname: form.fname.value,lname: form.lname.value,email: form.email.value}, function(data) {
			if(data.status) {
				$(form).children('p.error').html(data.msg).children('label').hide();
				$(form).children('button').attr('disabled', 'disabled');
				$(form).children('input').css('background', '#aeaeae').attr('disabled', 'disabled');
				$('#newsletter').html('Thank you for submitting the newsletter');
			} else {
				$(form).children('p.error').html('<label for="newsletter_email" class="error">'+data.msg+'</label>');
			}
			form.email.value = '';
			form.email.focus();
			$('#newsletter_indicator').hide();
		});
	},
	globalscript : function () {
		$('#newsletter input.txt-box').click(function(){
			$('input').css('border','1px solid #DEDEDE');
		});
		$("#pikame").PikaChoose({show_captions:false,show_prev_next:false});	
			/*tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
			imgLoader = new Image();// preload image
			imgLoader.src = tb_pathToImage;*/
	},
	loadAjaxPortfolio: function(gallerySlug,sectionSlug) { 
		//$('#gallery_indicator').show();
		var url = "/en/content/portfolio/gallery/";
		$.ajax({
		   type: "GET",
		   url: url,
		   data: "slug=" + gallerySlug + "&section=" + sectionSlug,
		   success: function(msg){
		     //alert( "Data Saved: " + msg );
		     $("#portfolio").html(msg);
			 $("#pikame").PikaChoose({show_captions:false,show_prev_next:false});
			 $('.lightbox').lightBox({fixedNavigation:true});
			 /*tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
			  imgLoader = new Image();// preload image
			  imgLoader.src = tb_pathToImage;*/
		/* var img = new Image();
		$(".gallery li:first-child img").hide();
		var imgpath = $(".gallery li:first-child img").attr("src");  
		$(img).load(function() {
		$(this).hide();
		$(".gallery li:first-child").html(this);
		$(this).animate({opacity: 1}, 1000).fadeIn("slow",function() {$(this).css("display","block") });		
		}).attr("src", imgpath);
		$('#gallery_indicator').hide();*/
		}		  
		 });
	}	
};

this.imagePreview = function(){
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		//this.title = "";	
		//var c = (this.t != "") ? "<br/>" + this.t : "...";
		$("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' /><br />"+ this.t +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		//this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});		
	$("a.preview").click(function(){
		return false;
	});
};


$(function() {
	Site.init();	
	Site.globalscript();
	imagePreview();	
});	