/*
Name: Javascript Functions
Version: 1.0
Description: BJavascript Functions para o site
Author: Alex Koti
Author URI: http://alexkoti.com
 */


jQuery(document).ready(function($){
	
	
	/**
	 * IE6 detect
	 */
	if($.browser.msie && $.browser.version=="6.0"){
		// alert("Im the annoying IE6");
	}
	
	
	/**
	 * SIMPLE SLIDER
	 * 
	 */
	if( $('#simple_slider_nav').length > 0 ){
		// contar slides
		var lis = $('#simple_slider ul li').length;
		// largura do holder
		$('#simple_slider ul').width( lis * 366 );
		$('#simple_slider ul').attr('rel', 1);
		$('#simple_slider ul li:first').addClass('current');
		
		$('#simple_slider_nav .btn_nav').click(function(){
			stop_slideshow();
			slide_go( $(this) );
		});
		
		start_slideshow();
	}
	
	function start_slideshow(){
		slideshow = setInterval( auto_slide, 15000 );
	}
	
	function auto_slide(){
		var active_item = $('#simple_slider_nav .active');
		var nav_itens = $('#simple_slider_nav .btn_nav');
		var total_navs = (nav_itens.length - 1);
		var next_obj = ( active_item.index() == total_navs ) ? nav_itens.first() : active_item.next();
		//alert( $(next_obj).html() );
		slide_go( $(next_obj) );
	}
	
	function stop_slideshow(){
		clearInterval(slideshow);
	}
	
	function slide_go( obj ){
		var holder = $('#simple_slider ul');
		var width = $('#simple_slider ul li:first').width();
		var active_slide = Number(holder.attr('rel'));
		var pos = holder.position();
		
		// definir direção e valor
		var direction = $(obj).attr('rel');
		
		if( direction == 'next' ){
			if( active_slide < lis ){
				var new_active = active_slide + 1;
				holder.attr('rel', new_active);
				var valor = '-='+width;
			}
		}
		else if( direction == 'prev' ){
			if( active_slide > 1 ){
				var new_active = active_slide - 1;
				holder.attr('rel', new_active);
				var valor = '+='+width;
			}
		}
		else{
			holder.attr('rel', direction);
			var valor = '-' + (width * (direction - 1));
		}
		
		// mover slide
		holder.animate({'left': valor }, 1000, 'swing');
		
		$('#simple_slider_nav .btn_nav').removeClass('active');
		$(obj).addClass('active');
	}
	
	
	/**
	 * COLORBOX
	 * 
	 */
	if( $("#clipping_list").length ){
		$("#clipping_list a").colorbox({
			maxWidth:"90%",
			maxHeight:"90%",
			current:"{current} de {total}",
			previous:"anterior",
			next:"próxima",
			close:"fechar"
		});
	}
});
