$(document).ready(function() {
													 

		$("#post_blog").click(function(event){
		  $.ajax({
			   type: "POST",
			   url: "ajaxtpl/post_blogs.php",
			   data: "name="+$("#name").val()+"&email="+$("#email").val()+"&comment="+$("#comment").val()+"&rano="+$("#rano").val(),
			   beforeSend:  function(){
         $("#ajax_loader").show();
        },
			   success: function(msg){
					if(msg == 'Your blog has been posted successfully.'){
					$("#name").val("");
					$("#email").val("");
					$("#comment").val("");
					$("#char").text("100");
	        $("#post_blog_frm img:first").attr("src","lib/secure.php?v="+new Date().getTime());
					$('#blog_form_container').slideUp();
					}
				$("#ajax_loader").hide();
			   $("#rano").val("");
				 alert( "" + msg );
			   }
			 });
		});
		 
		$("#post_comment").toggle(function(){
        $('#blog_form_container').slideDown();
     },
     function(){
        $('#blog_form_container').slideUp();
      });

		 	$("#comment").keyup(function(event){
			if($("#comment").val().length > 100)
			{
			$("#comment").val($("#comment").val().substring(0, 100));
			}
		   else
		   {
		   var length_str = 100-$("#comment").val().length; 
		   if(length_str == 0)
		   $("#char").html("0");
		   else
		   $("#char").html(length_str);
		   }
		 });

    $("a.video_testimonials").fancybox({ 'hideOnContentClick': false, 'frameWidth': 520, 'frameHeight': 375, 'callbackOnShow': loadLargeTestimonial, 'callbackOnClose': unloadLargeTestimonial });

	/* Content slide scroller */
	var current_content_area = null;
	var total_slide_length = 0;
	var current_position = 0;
  var current_slide_length = 0;
    
	$('#content_slider li').each(function (){
	   total_slide_length = total_slide_length + $(this).height();
	});

	$('#services_column div').click(function() {
		var temp_content_area = '#slide_'+this.id;	
    var slide_count = 0;
    current_slide_length = 0;
    var content_slides = $('#content_slider li');
		if(current_content_area != temp_content_area){
		current_position = content_slides.index($(temp_content_area));
			
			while(slide_count <= current_position){
        current_slide_length = current_slide_length + $(content_slides.get(slide_count)).height();
        slide_count++;
			}
			margin_offset = -(current_slide_length - $(temp_content_area).height());
			$('#content_slider').animate({ marginTop: margin_offset}, 600);
			$('#slide_container').animate({ height: $(temp_content_area).height()}, 600);
			current_content_area = '#slide_'+this.id;
		}
    var targetOffset = $('#slide_container').offset().top;
		$('html, body').animate({scrollTop:targetOffset}, 'slow'); 
	});
	
	$('#slide_container').height($('#slide_default').height());
	
	$("#pageflip").css('top', '-1000px');
	
	$('#testimonial_tab').click(function(){
		$('#player_buttons').css('background-position','-29px top');
	});
	$('#tvad_tab').click(function(){
		$('#player_buttons').css('background-position','left top');
	});
	$('#newsletter_link').click(function(){
		show_big_curl();
	});
});

function popitup(url) {
	var newwindow = '';
	if (newwindow.location && !newwindow.closed) 
	{ newwindow.location.href = url; newwindow.focus(); } 
	else 
	{ newwindow=window.open(url,'call_now','menubar=0,resizable=0,location=0,status=0,scrollbars=0,width=606,height=440') ; }
}

function show_big_curl(){
	$("#pageflip").css('top', '0');
	$("#pageflip_small").css('top', '-155px');
}

function show_small_curl(){
	$("#pageflip_small").css('top', '0px');
	$("#pageflip").css('top', '-500px');
}
	
function full_screen() {
	$("a.video_testimonials").click();
}

function newsletter(fname,email) { 
	 $.ajax({
		 type: "POST",
		 url: "ajaxtpl/nl_subscriber.php",
		 data: "news_name="+fname+"&news_email="+email,
		 success: function(msg){
		 //alert( "" + msg );
		 }
	 });
}
