function setSiteURL() {
        window.site = "../index.php/";
} 

//scroller
$(document).ready(function() {
	$(".scroll").click(function(event){
		event.preventDefault();
		var full_url = this.href;
		var parts = full_url.split("#");
		var trgt = parts[1];
		var target_offset = $("#"+trgt).offset();
		var target_top = target_offset.top;
		$('html, body').animate({scrollTop:target_top}, 1000);
	});
});

//polling
$(document).ready(function(){
	 $("input[name='polli']").click(function() {
               // alert('s'); return false;
		var defaultValue = $("input[@name='polli']:checked").val();
		var site="../index.php/";
		$.ajax({
	   		type:"POST",
	   		url:""+site+"polling/poll_result/"+defaultValue,
			data:$(this.elements).serialize(),
			success:function(response){
				$("#polling_response").html(response);
				$('#polling_response').modal({
					containerCss:{
						backgroundColor:"#cccccc",
						borderColor:"#f1f1f1",
						height:250,
						padding:10,
						width:300						
					}
				});
			},
			dataType:"html"
		}); 
	   	return false;
	 });
});

//guestbook
$(document).ready(function(){
	var site="../index.php/";
	
	$("#loading").hide();
	$("#gb").submit(function(){
	   	$.ajax({
	   		type:"POST",
	   		url:""+site+"guestbook/save",
			data:$(this.elements).serialize(),
			success:function(response){
				$("#gb_response").html(response);
	    		//$("#gb_response").fadeIn("slow");
				$('#gb_response').modal({
					containerCss:{
						backgroundColor:"#cccccc",
						borderColor:"#f1f1f1"						
					}
				});
			},
			dataType:"html"
		}); 
	   	return false;
	});
});

//loading indicator
$(document).ready( function() {
	setSiteURL();
	$("#loading").hide();
	$("#loading").ajaxStart(function(){
			var x = ($(window).width()/2)-($(this).width()/2);
			var y = ($(window).height()/2)-($(this).height()/2);

		  	$(this).show().css({ position 		: "absolute",
				                    top        	: "900px",
				               		left      	: x+"px"
			});
	});

	$("#loading").ajaxStop(function(){
      $(this).hide();
	});
	
	$("#submit").click(function(){
		return false;
	});
});	
	
function hide(div){
	$(div).hide("slow");	
};

function show(page,div){
	$.ajax({
		url:""+site+""+page+"",
		
		beforeSend:function(response){
			$(div).fadeOut("slow");
		},
		success: function(response){			
    		$(div).html(response);
    		$(div).fadeIn("slow");
    		
    		try{FB.XFBML.parse();      }catch(ex){}
  		},
                error:function (xhr, ajaxOptions, thrownError){
                    alert(xhr.status);
                   
                }  ,
  		dataType:"html"  		
  	});
  	return false;
};


function show2(page,div){
	//alert("testttt"); return false;
	$.ajax({
		url:page,
		
		beforeSend:function(response){
			$(div).fadeOut("slow");
		},
		success: function(response){			
    		$(div).html(response);
    		$(div).fadeIn("slow");
  		},
		
		error:function (xhr, ajaxOptions, thrownError){
            alert(xhr.status);                    
        },
		
  		dataType:"html"  		
  	});
  	return false;
};



		
