var site_domain = $('base').attr('href');

$(document).ready(function() {
	
	//Jokes cycle
	$('#breaking_news').cycle({
		fx: 'fade',
		speed:  3000 
	});
	
	//Load more list blogs
	$(".blogs-more").live("click",function() {
		var ID = $(this).attr("id");
		if(ID) {
			$("#load-more-container").html("<img src=\""+ site_domain +"images/moreajax.gif\" class=\"margin-right20\"/><span class=\"text20\">Loading</span>");
		
			$.ajax({
				type: "GET",
				url: site_domain + "cont_posts_ajax_more.php",
				data: "data="+ ID +"&ajax_loaded=1",
				cache: false,
				success: function(html){
					$("#list-container").append(html);
					$("#load-more-container").remove(); // removing old more button
				}
			});
		}
		else {
		//$(".morebox").html("The End");// no results
		}
		return false;
	});
	
	//Load more list blogs
	$("a.pag_num, a.pag_prev, a.pag_next").live("click",function() {
		var ID = $(this).attr("id");
		var id_split = ID.split("_ID_");
		
		var link = id_split[0].replace("LINK_", "");
		
		if(id_split[1]) {
			$("#posts-paginate-container").html("<span class=\"loading\">Loading...</span>");

			$.ajax({
				type: "GET",
				url: site_domain + "cont_posts_paginate_ajax.php",
				data: "ajax_loaded=1&page="+id_split[1]+"&link="+link,
				cache: false,
				success: function(html){
					$("#posts-paginate-container").html(html);
				}
			});
		}
		else {
			$("#posts-paginate-container").html('<span class="red">Posts could not be loaded<span>');
		}
		return false;
	});
	
	//Blog archive
	$('a.expand').click(function() {
	     var id = $(this).attr('id');
	     $('#expandbox' + id).slideToggle();
	     return false;
	});
	
	//Forgot password slide
	$("#forgot_password_link").click(function() {
		$("#forgot_password_more").slideToggle("fast");
		return false;
	}); 
	
	$("a[rel^='prettyPhoto']").prettyPhoto({theme:'facebook', social_tools:''});
	
	/* GALLERY ROLLOVER */
	
	$("ul.gallery li").hover(function() {
		$('img', this).stop().animate({"opacity": "0.4"}, "slow");
		$(this).siblings('div.magnifier').stop().animate({"opacity": "1"}, "slow");
		$('div.magnifier', this).stop().animate({"opacity": "1"}, "slow");
	},
	function() {
		$('img', this).stop().animate({"opacity": "1"}, "slow");
		$(this).siblings('div.magnifier').stop().animate({"opacity": "0"}, "slow");
		$('div.magnifier', this).stop().animate({"opacity": "0"}, "slow");
	});
	
	/* MAGIC LINE */
	if (($.browser.msie && $.browser.version.substr(0,1) < 7) || navigator.userAgent.toLowerCase().indexOf('chrome') > -1 || navigator.userAgent.toLowerCase().indexOf('safari') > -1) {
	} else {

	    var $el, leftPos, newWidth, $mainNav = $(".example-one");
	
	    $mainNav.append("<li id='magic-line'></li>");
	    var $magicLine = $("#magic-line");
	
	    $magicLine
	        .width($(".current_page_item a").width())
	        .css("left", $(".current_page_item a").position().left)
	        .data("origLeft", $magicLine.position().left)
	        .data("origWidth", $magicLine.width());
	
	    $(".example-one li a").hover(function() {
	        $el = $(this);
	        leftPos = $el.position().left;
	        newWidth = $el.width();
	        $magicLine.stop().animate({
	            left: leftPos,
	            width: newWidth
	        });
	    }, function() {
	        $magicLine.stop().animate({
	            left: $magicLine.data("origLeft"),
	            width: $magicLine.data("origWidth")
	        });
	    });
	}
});


//RECAPTCHA
var RecaptchaOptions = { theme : 'clean' };

//Validate the Recaptcha' Before continuing with POST ACTION
function validateCaptcha() {
    challengeField = $("input#recaptcha_challenge_field").val();
    responseField = $("input#recaptcha_response_field").val();
    //alert(challengeField);
    //alert(responseField);
    //return false;
    var html = $.ajax({
    type: "POST",
    url: "ajax.recaptcha.php",
    data: "recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" + responseField,
    async: false
    }).responseText;
 
    if(html == "success") {
				
		//Submit the form
		$('#register').live('submit', function() {
			$.ajax({ // create an AJAX call...
				data: $(this).serialize(), // get the form data
				type: $(this).attr('method'), // GET or POST
				enctype: $(this).attr('enctype'),
				url: 'cont_register.php', // the file to call
				success: function(data) { // on success..
					$("#register-content").html(data);
				}
			});
			return false; // cancel original event to prevent form submitting
		});
			
		//Indicate a Successful Captcha
		$("#captchaStatus").html("Success!");
		// Uncomment the following line in your application
        //return true;
       
        return false;
    }
    else  {
        $("#captchaStatus").html("Your captcha is incorrect. Please try again");
        Recaptcha.reload();
        return false;
    }
}
