/*

*/

jQuery(document).ready(function() {
    jQuery('#thecarousel').jcarousel({
        
    });
});

var $j = jQuery.noConflict();
$j(document).ready(function(){
	$j("#tagcloud").hide();
	
	$j(".tag-link a").each(function() {
		$j(this).toggle(function() {
			$j("#tagcloud").slideDown(500);
			return false;
		}, function() {
			$j("#tagcloud").slideUp(500);
		});
	});
	
	/*var max_width = 460;
	var selector = '.single img';

	$j(selector).each(function(){
		var width = $j(this).width();
		var height = $j(this).height();

		var ratio = (height / width );
		var new_width = max_width;
		var new_height = Math.floor(new_width * ratio);

		$j(this).height(new_height).width(new_width);
	});*/
	
	var max_width_small = 309;
	var selector = 'img.fixed-small';

	$j(selector).each(function(){
		var width = $j(this).width();
		var height = $j(this).height();

		var ratio = (height / width );
		var new_width = max_width_small;
		var new_height = Math.floor(new_width * ratio);

		$j(this).height(new_height).width(new_width);
	});
	
	var max_width_big = 629;
	var selector = 'img.fixed-big';

	$j(selector).each(function(){
		var width = $j(this).width();
		var height = $j(this).height();

		var ratio = (height / width );
		var new_width = max_width_big;
		var new_height = Math.floor(new_width * ratio);

		$j(this).height(new_height).width(new_width);
	});
	
	/*var user_width_big = 100;
	var selector = '.sidebar-img img';

	$j(selector).each(function(){
		var width = $j(this).width();
		var height = $j(this).height();

		var ratio = (height / width );
		var new_width = user_width_big;
		var new_height = Math.floor(new_width * ratio);

		$j(this).height(new_height).width(new_width);
	});*/
	
	
	
	//find the first item and set it to active
	$j(".gallery li:first").addClass("active");

	//set the opacity of all images to invisible
	$j(".gallery li").stop().animate({ opacity: '0' }, 1);

	//set the first image to be visible again
	$j(".gallery li:first").stop().animate({ opacity: '1' }, 1);

	rotate = function() {
		$prev = $j('.gallery li.active');
		$active = $j('.gallery li.active').next(); //Move to the next item
		if ($active.length === 0) { //If items reaches the end...
			$active = $j('.gallery li:first'); //go back to first
		}

		//remove the active class from all the items
		$j('.gallery li').removeClass('active');

		//set the new item to active
		$active.addClass('active');

		//animate the new item to be visible
		$active.stop().animate({ opacity: '1' }, 2500, function() { 
			$prev.stop().animate({ opacity: '0'}, 1); 
		});
	};

	//Rotation  and Timing Event
	rotateSwitch = function() {
		play = setInterval(function() { //Set timer - this will repeat itself every X seconds
			rotate(); //Trigger the paging and slider function
		}, 8000); //Timer speed in milliseconds (5 seconds)
	};

	rotateSwitch();

	//On Hover
	$j(".window li").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation timer
	});
});
