$(function(){

		if(typeof String.prototype.trim !== 'function') {
				  String.prototype.trim = function() {
					return this.replace(/^\s+|\s+$/g, ''); 
				  }
		}

	var actions = {
		'home': function(){
			$('.slideshow').cycle({
				fx: 'scrollHorz',
				timeout: 5000,
				pager: '.index_pager',
				pagerAnchorBuilder: function(idx){
					return $('.pager li:eq('+idx+')');
				}
			});
		},
		'pleno': function(){
			$('.changeOver li').click(function(){
				$(this).toggleClass('active');
			});	
		},
		'portfolio': function(){
			$('.categories li').click(function(){
				var cat = $(this).attr('class').replace('active','').trim();
				$('.categories li.active').removeClass('active');
				$(this).addClass('active');
				
				$('#shadow .content').cycle('destroy').empty();
				
				$.getJSON('portfolio/index.php', {category: cat}, function(json){
					$.each(json, function(idx, src){
						$('.content').append( $('<img>').attr('src', src) );
					});
					
					$('#shadow .content').cycle({
						next: '.next',
						timeout: 0,
						fx: 'scrollHorz',
						prev: '.prev',
						pager: '#clientes',
						pagerAnchorBuilder: function(idx, elem){
							var img = $('<img>').attr('src', elem.src);
							img.height(82).width(140);
							
							return $('<li>').addClass('margem').append(img);
						}
					});					
				}); 
			});
			
			$('.categories li:first').click();
		}
	};
	
	
	/* call the func by page */
	$('body').data('page') && actions[$('body').data('page')]();
});
