
$(document).ready(function() {
   

	if($(".secure").length >= 1) {
		$.get("/token.php",function(txt){
        	$(".secure").append('<input type="hidden" name="ts" value="'+txt+'" />');
	    });
    }
	
	    
    $('#newsletter2').validate();
    
    $('#newsletter2').submit(function(){
    	if($('#newsletter2').valid()) {
        $.ajax({
            url: base+"?ajax=newslettersubscription", 
                data: $(this).serialize(),
                type: $(this).attr('method'),
                dataType: 'json',
                success: function(response){
                    if (response['status']==false) {
                        showMessage('Newsletter subscription failed!',$('.newsletteremail').val()+' is already subscribed to our newsletter!','error');
                    } else {
                        showMessage('You have been subscribe to our newsletter successfully.','Thank you for your subscription.','success');
                        window.location=base+"thanks_newsletter";
                        $('#newsletterbox').hide('fast');
                    }
             }
        
        });
        }
         return false;
    });
});

jQuery(function($){
        $('<div id="loadingBox"><div id="loadingimg"></div><div id="loading"></div></div>').appendTo(document.body).hide();
/*
        $('#loadingBox').ajaxStart(function() {
           $(this).show();
        }).ajaxStop(function (){
           $(this).hide();
        });
*/
});

/**
    display a message.
    @title = Title of the message
    @message = optional text
    @type = ["notification" | "error" | "success"]
**/
function showMessage(title, message, type) {
		alert(title + "\n" + message);
		return false;
        $("#messageTitle").html(title);
        $("#messageBody").html(message);
        $("#ajaxMessage").show("slow");
        /* this cause layout problem in IE7, the active tabs freaking out */
        if(type=="success" || type=="notification") setTimeout('$("#ajaxMessage").hide("slow");', 5000);
}

// function 
function sGallery(id) {

		$.ajax({
            url: base+"gallery?gid="+id, 
                 type: "POST",
                 dataType: 'json',
                 success: function(r){
			            $("#sub_gallery").html(r.gallery);
			            $("#g_images").html(r.images);
			            $("#g_desc").html(r.g_desc);
			            init();
			            s=2;
                 }
        });
}


function init(){

//Activate FancyBox
    $(".galleryimg").fancybox({
		'zoomSpeedIn':	0, 
		'zoomSpeedOut':	0, 
		'overlayShow':	true,
		'padding'	:	5
    });

//Activate FancyBox
    $(".gallerytxt").fancybox({
		'zoomSpeedIn':	0, 
		'zoomSpeedOut':	0, 
		'overlayShow':	true,
		'padding'	 :	5,
		'frameWidth' :	800,
		'frameHeight':	550
    });
}




function m_show(i,p) {

	if(i > $(".m_images").length ) i = 1;
	if(p == "r") {
		if(i < $(".m_images").length )  {
			$(".m_images").each(function(){
				index = $(".m_images").index( $(this) );
				if(index == i) {
					$(this).show();
				} else {
					$(this).hide();		
				}
			});
			ss=ss+1;	
		}
	} else {
		if(i > 0 )  {	
			$(".m_images").each(function(){
				index = $(".m_images").index( $(this) );
				if(index == i-1) {
					$(this).show();
				} else {
					$(this).hide();		
				}
			});
			ss=ss-1;
		}
	}	
}


function show(i,p) {

	if(i > $(".panel").length ) i = 2;
	if(p == "r") {
		if(i < $(".panel").length )  {
			$(".panel").each(function(){
				index = $(".panel").index( $(this) );
				if(index == i || index == i+1) {
					$(this).show();
				} else {
					$(this).hide();		
				}
			});
			s=s+2;	
		}
	} else {
		if(i > 0 )  {	
			$(".panel").each(function(){
				index = $(".panel").index( $(this) );
				if(index == i-1 || index == i-2) {
					$(this).show();
				} else {
					$(this).hide();		
				}
			});
			s=s-2;
		}
	}	
}



