$(document).ready(function(){
	
    image_gallery();
	
	// SEARCH & NEWSLETTER TEXT INPUTS
    function text_inputs() {
        // set the default text
    	$('input#search, div#page_footer_email input[type="text"]').focus(function(){
    		var value = this.value;
    		var title = this.title;
    		if (value == title) {
    			$(this).val("");
    		};
    	});
	
    	// if it's blank then reset back the title attribute
    	$('input#search, div#page_footer_email input[type="text"]').blur(function(){
    		if(!$(this).val().length){
    			$(this).val(this.title);
    		}
    	});
    }

	
    
    $('ul.tabbed_anchors').tabs();
    
    
    // ARTICLE TABS ON HOMEPAGE
    /*function article_tabs() {    
        $(".home div#popular_articles").hide();

        $("ul#navigation_articles li a").click(function(){
            $("ul#navigation_articles li.cur").removeClass("cur");
            $(this).parent().addClass("cur");

            var show_div = $(this).attr("href");
            $("div.article_listing").hide();
            $("div"+show_div).show();

            return false;
        });
    }*/
    
    
    
    // GIVING CLASS TO LAST CHILD LIST ITEM
    function last_child() {
        $("div#forum_activity ul li:last,div.comment_listing_sub ul li:last,ul#about_subnav li:last,ul#docs_subnav li:last").addClass("last");
    }
    
        
    
    // ARTICLE DROP CAP
    function dropcap() {
        var firstp  = $(".article div#content_pri > p:first-child").html();
        var words   = firstp.split(' ');
        var letters = words[0].split('');

        letters[0]  = '<span class="dropcap '+letters[0]+'">'+letters[0]+'</span>';
        words[0]    = letters.join('');
        firstp      = words.join(' ');
        $(".article div#content_pri > p:first-child").html(firstp);
    }



	// IMAGE GALLERY
	function image_gallery() {
		$('div.image_gallery ul li a').click(
			function(){
			
			    var $kids = $(this).children('img');
			
				$('div.image_gallery ul li a img').removeClass('cur');
				$($kids[0]).addClass('cur');

				var caption = $(this).next('span').html();
				$('div.mainimage p').replaceWith('<p>' + caption + '</p>');
				
                var new_src = $(this).attr('href');
		    	$('div.mainimage img').attr('src', new_src);
		    	return false;
			}
		);
	}
	

       
    // CALL ALL THE FUNCTIONS
	text_inputs();
    //article_tabs();
    last_child();
    if($(".article div#content_pri > p:first-child").length > 0) {
        dropcap();
    }
    imagePreview();


    
});



// IMAGE PREVIEW
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 : "";
				
		var img_url = $(this).children('img').attr('src');
		
		$("body").append("<p id='imagepreview'><img src='"+ img_url +"' alt='Image preview' />"+ c +"</p>");				 
		$("#imagepreview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("slow");				
    },
	function(){
		this.title = this.t;	
		$("#imagepreview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#imagepreview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
				
};