var $j1=jQuery.noConflict();$j1(document).ready(function(){var HeaderScrolled=false;var searchVisible=false;function FadeHeaderOut(){$j1("#header_top").fadeTo("slow",0.7);HeaderScrolled=true}function FadeHeaderIn(){$j1("#header_top").stop().fadeTo("fast",1);HeaderScrolled=false}$j1(window).scroll(function(){if(!HeaderScrolled){FadeHeaderOut()}var scrollTop=$j1(document).scrollTop();if(scrollTop==0){FadeHeaderIn()}if(searchVisible){toggleSearch()}});$j1("#header_top").bind("mouseenter",function(){FadeHeaderIn()});$j1("#header_top").bind("mouseleave",function(){var scrollTop=$j1(document).scrollTop();if(scrollTop!=0){FadeHeaderOut()}})});


var $j2=jQuery.noConflict();



/* Start of  Category Gallery JS */ 

function j2_initCallback(carousel) {

    $j2('div.gallery_nav a.next',carousel.container).bind('click', function() {

        carousel.next();

        return false;

    });	
	
	 $j2('div.gallery_nav a.prev',carousel.container).bind('click', function() {

        carousel.prev();

        return false;

    });		

};

function category_itemLoadCallback(carousel, state)
{    
	var item_parent=$j2("li.jcarousel-item-"+carousel.first,carousel.container);
	var item_wrapper=item_parent.find('.item_wrapper');
	
	
	if(!item_wrapper.length)
	{
		
		var gallery_item=item_parent.find('div.gellery_item');
		gallery_item.each(function(i){
			 //alert(i);
			var item_cr=$j2(this).find('a.image_linker');
			var listImg = item_cr.attr('title');
			var luimg = new Image();
			
			$j2(luimg).css("opacity", "0.0").load( function(){
				
				item_cr.append(this).removeAttr('title');
				$j2(this).animate({opacity: 1.0}, 500);
			}).attr('src', listImg);
			
			
			
			});
		  item_parent.wrapInner('<div class="item_wrapper" />');
	}

};

/* end of cat js */

var $j3=jQuery.noConflict();

$j3(document).ready(function() {

$j3('.gellery_item').hover(function() {

        $j3(this).children('.info').fadeIn();

    }, function() {

        $j3(this).children('.info').fadeOut();

    });

});

/* js for post-1 gallery */

var $j7=jQuery.noConflict();

function post_type1_itemLoadCallback(carousel, state)
{    
	var item_parent=$j7("li:nth-child("+carousel.first+")",carousel.container);
	
	var item_wrapper=item_parent.find('.item_wrapper');
	
	
	if(!item_wrapper.length)
	{
		//alert('exist');
			var item_cr=item_parent.find('a');
	        
	  		var listImg = item_cr.attr('title');
			var luimg = new Image();
			
			$j7(luimg).css("opacity", "0.0").load( function(){
				
				item_cr.append(this).removeAttr('title');
				$j7(this).animate({opacity: 1.0}, 500);
				item_cr.wrap('<div class="item_wrapper" />');
			}).attr('src', listImg);
				
			 	
	  
	}

};

function post_gallery_1AfterAnimation(carousel, item, idx, state) {

 var parent=$j7(carousel.container).parent().parent();

  $j7(".post-1-content .post-1-item-active",parent).removeClass("post-1-item-active");

  $j7(".post-1-item-"+idx,parent).addClass("post-1-item-active");

};

function post_gallery_1initCallback(carousel) {	

    $j7('.altNext',carousel.container).bind('click', function() {

        carousel.next();

        return false;

    });

    $j7('.altPrevious',carousel.container).bind('click', function() {

        carousel.prev();

        return false;

    });	

};

$j7(document).ready(function() {
    $j7(".post-type-1 .carousel").jcarousel({

        scroll: 1,

	    itemVisibleInCallback: {

            onAfterAnimation:post_gallery_1AfterAnimation

        },
        initCallback: post_gallery_1initCallback,
		
       itemLoadCallback: {onBeforeAnimation: post_type1_itemLoadCallback},
        buttonNextHTML: null,

        buttonPrevHTML: null

    });

});

/* gallery for post-2 */

function post_type2_itemLoadCallback(carousel, state)
{    
	var item_parent=$j2("li.jcarousel-item-"+carousel.first,carousel.container);
	var item_wrapper=item_parent.find('.item_wrapper');
	
	
	if(!item_wrapper.length)
	{
		//alert('exist');
		var item_cr=item_parent.find('a');
	  item_cr.wrap('<div class="item_wrapper" />');
	  		var listImg = item_cr.attr('title');
			var luimg = new Image();
			
			$j2(luimg).css("opacity", "0.0").load( function(){
				
				item_cr.append(this).removeAttr('title');
				$j2(this).animate({opacity: 1.0}, 500);
			}).attr('src', listImg);
				
				
	  
	}

};

function post_gallery_2AfterAnimation(carousel) {	

   

    $j2('.altNext',carousel.container).bind('click', function() {

        carousel.next();

        return false;

    });

    $j2('.altPrevious',carousel.container).bind('click', function() {

        carousel.prev();

        return false;

    });	

};

$j2(document).ready(function() {


    $j2(".post-type-2 .carousel").jcarousel({

        scroll: 1,

	    itemVisibleInCallback: {

            onAfterAnimation:post_gallery_2AfterAnimation

        },
		itemLoadCallback: {onBeforeAnimation: post_type2_itemLoadCallback},

        buttonNextHTML: null,

        buttonPrevHTML: null

    });

	

 

});

/* START: Custom scrolling */

var CustomScroller = {};

CustomScroller.clickDistance = 400; // in pixels

CustomScroller.clickDuration = 300; // in milliseconds

CustomScroller.downButtonMouseDown = function (target, copyDiv, wrapperDiv, objOnClickFunction) {

    

    if (typeof (objOnClickFunction) != "undefined") {

        objOnClickFunction();

    }

    wrapperDiv.data("clickStart", new Date().getTime());

    var delta = copyDiv.height() + copyDiv.position().top - wrapperDiv.height();

    if (delta > 0) {

        target.parent().children(".up").removeClass("disabled");

    }

    copyDiv.animate({ "top": "-=" + delta }, { "duration": "slow", "easing": "swing",

        "complete": function () { CustomScroller.disableButtons(wrapperDiv, copyDiv); }

    });

};

CustomScroller.downButtonMouseUp = function (target, copyDiv, wrapperDiv) {

    var intTimeElapsed = new Date().getTime() - wrapperDiv.data("clickStart");

    copyDiv.stop(true);

    /* If it was a click, execute the minimum delta animation */

    if (intTimeElapsed < CustomScroller.clickDuration) {

        var intDelta = Math.min(CustomScroller.clickDistance, copyDiv.height() + copyDiv.position().top - wrapperDiv.height());

        copyDiv.animate({ "top": "-=" + intDelta },

                    { "duration": "slow", "complete": function () { CustomScroller.disableButtons(wrapperDiv, copyDiv); }

                    });

    }

};

CustomScroller.upButtonMouseDown = function (target, copyDiv, wrapperDiv, objOnClickFunction) {

    if (typeof (objOnClickFunction) != "undefined") {

        objOnClickFunction();

    }

    wrapperDiv.data("clickStart", new Date().getTime());

    var delta = copyDiv.position().top * -1;

    if (delta > 0) {

        target.parent().children(".down").removeClass("disabled");

    }

    copyDiv.animate({ "top": "+=" + delta }, { "duration": "slow", "easing": "swing",

        "complete": function () { CustomScroller.disableButtons(wrapperDiv, copyDiv); }

    });

};

CustomScroller.upButtonMouseUp = function (target, copyDiv, wrapperDiv) {

    var intTimeElapsed = new Date().getTime() - wrapperDiv.data("clickStart");

    copyDiv.stop(true);

    /* If it was a click, execute the minimum delta animation */

    if (intTimeElapsed < CustomScroller.clickDuration) {

        var intDelta = Math.min(CustomScroller.clickDistance, copyDiv.position().top * -1);

        copyDiv.animate({ "top": "+=" + intDelta }, { "duration": "slow",

            "complete": function () { CustomScroller.disableButtons(wrapperDiv, copyDiv); }

        });

    }

};

CustomScroller.disableButtons = function (wrapperDiv, copyDiv) {

    if (copyDiv.position().top >= 0) {

        wrapperDiv.find(".up").addClass("disabled upDisabled");

    } else if (copyDiv.height() + copyDiv.position().top <= wrapperDiv.height()) {

        wrapperDiv.find(".down").addClass("disabled downDisabled");

    }

};

CustomScroller.init = function (strSelector, objOnClickFunction) {

      

    var copyDiv = $j2(strSelector);

 

    copyDiv.each(function () {

        

        var oldHeight = Math.round($j2(this).height()) +44;

		       temp=$j2(this).parent(".post-1-item");

        $j2(this).wrap("<div class='scrollableDiv' />");

        var wrapperDiv = $j2(this).parent();

        wrapperDiv.css({ height: oldHeight + "px" });

        $j2(this).css({ overflow: "visible", position: "absolute", height: "auto" }).addClass("copyDiv");

        if (wrapperDiv.height() < copyDiv.height()) {

            wrapperDiv.append($j2("<div class='controls'><a class='up'>Up</a><a class='down'>Down</a></div>"))

                .addClass("scrollableDivWithControls");

            wrapperDiv

                    .find(".down")

                    .mousedown(function () {

                        CustomScroller.downButtonMouseDown($j2(this), copyDiv, wrapperDiv, objOnClickFunction);

                    })

                    .mouseup(function () {

                        CustomScroller.downButtonMouseUp($j2(this), copyDiv, wrapperDiv);

                    });

            wrapperDiv

                    .find(".up")

                    .mousedown(function () {

                        CustomScroller.upButtonMouseDown($j2(this), copyDiv, wrapperDiv, objOnClickFunction);

                    })

                    .mouseup(function () {

                        CustomScroller.upButtonMouseUp($j2(this), copyDiv, wrapperDiv);

                    });

            CustomScroller.disableButtons(wrapperDiv, copyDiv);

        }

      temp.hide();

    });

};

/* END: Custom scrolling */
(function($) {

	var optiontg		= new Array;
	var obj_img			= new Array;
	var theClass		= new Array;
	var imageposition	= new Array;
	var preloadInterval = new Array;
	
	$.fn.tgPreload= $.fn.tgPreload = function(options){
		
		init = function(tgp){
			optiontg[tgp.id] = $.extend({}, $.fn.tgPreload.defaults, options);
			 
					obj_img[tgp.id]			= new Array();
					theClass[tgp.id]		= new Array();
					imageposition[tgp.id]	= 0;
					
					
					$.each($('#'+tgp.id+' .' + optiontg[tgp.id].childClass + ''), function(i,item){
						theClass[tgp.id][i] = $(item);
						obj_img[tgp.id][i] = $(item).find('img');

						obj_img[tgp.id][i].css({'display': 'block', 'opacity' : '0'});
					});
				
					$.transitionpreload(tgp);
			
		};
		
		// transitions
		$.transitionpreload = function(tgp){
			preloadInterval[tgp.id] = setInterval(function() { $.ownanimate(tgp) }, optiontg[tgp.id].speed);
		};
		
		$.ownanimate = function(tgp){
				//alert(imageposition[tgp.id]);
				if  (imageposition[tgp.id] == obj_img[tgp.id].length) {
					clearInterval(preloadInterval[tgp.id]);
					return;
				}

				$(obj_img[tgp.id][imageposition[tgp.id]]).animate({opacity: 1.00});
				$(theClass[tgp.id][imageposition[tgp.id]]).removeClass('ploader');
				
				imageposition[tgp.id]++;
				
		};
		
		this.each (
			function(){ init(this); }
		);
	};
	
	// default values
	$.fn.tgPreload.defaults = {	
		speed : 200,
		animateSpeed : 400,
		childClass : ""
	};	
	
})(jQuery);

$j2(document).ready(function() {
	
$j2('#cat_posts').tgPreload({'childClass' : 'post-item'});

});

jQuery(document).ready(function() {
	jQuery('.like_count').click(function() {
		if(jQuery(this).attr('disabled'))
     	return;
		var option =0,post = jQuery(this).attr('id').substr(4);
		
		jQuery(this).attr('disabled',true);
		 
		var parent=jQuery(this);
		
		jQuery.ajax({
			type: 'POST',
			data: 'emo_vote=1&option='+option+'&post='+post,
			dataType: 'jsonp',
			success: function(j) {
				if(j.response.status == 200) {
					var i = 0,str,locale;
				
					parent.text(j.response.numbers['vote_0']);
					
					
				} else if(j.response.status == 500) {
					alert('An error occurred, please try again');
				}
			}
		});
	});
});


function mycarousel_cat_call_back(carousel) {
 
 
    $j2('#cat_posts #snext').bind('click', function() {
        carousel.next();
		
        return false;
    });

    $j2('#cat_posts #sprev').bind('click', function() {
        carousel.prev();
        return false;
    });
};

$j2(document).ready(function() {
   $j2("#cat_slider > ul").jcarousel({
        auto: 6,
        wrap: 'last',
        scroll: 4,
		initCallback: mycarousel_cat_call_back,
        buttonNextHTML: null,

        buttonPrevHTML: null

    });

});
