/* 
	OpenK Tecnologia em Sistemas LTDA
	Av. Athayde de Deus Vieira, 69 - Tibery
	CEP 38405-150 - Uberlândia/MG
	+55 (34) 3238-2222 - comercial@openk.com.br

	Author: Abraao P. M. R. B. Junior
	E-mail: abraao.junior@openk.com.br
*/
function trataLinks( txt ) {
	var arrayTxt = txt.split(" ");
	var qtdPecas = arrayTxt.length;
	var newTxt = "";
	for(i=0; i<qtdPecas; i++){
		if( arrayTxt[i].substring(0,7) == "http://" )
			txtTmp = '<a href="'+arrayTxt[i]+'" target="_blank">'+arrayTxt[i]+'</a>';
		else
			txtTmp = arrayTxt[i];
		newTxt += " " + txtTmp;
	}
	return newTxt;
}
$(document).ready(function(){
	if($('input[name="shipperPhone"]').length > 0){
		$('input[name="shipperPhone"]').mask('(99)9999-9999');
	}
	function showTweets(elem, username, number){
		var html = '';

		var tweetFeed = 'http://twitter.com/status/user_timeline/' + username + '.json?count=' + number + '&callback=?';
		$.getJSON(tweetFeed, function(d){
			$.each(d, function(i,item){
				html += '<div>'+trataLinks(item.text)+'</div>';
			});
			elem.html(html);
			if($('.textTwitter div').length > 1){
				$('.textTwitter').cycle({
					fx: 'scrollLeft',
					speed: 500,
					timeout: 5000,
					cleartypeNoBg: true,
					easing: 'easeInOutCubic',
					pause: 1
				});
			}
		});
	}
	showTweets($('.textTwitter'), 'cuboamarelo', 10)
	$('.cntMenuPrinc ul li').each(function(){
		var href = escape(unescape($(this).children('a').attr('href')));
		var winHref = '/' + escape(unescape(window.location.href.split('cuboamarelo.com.br/')[1]));
		if(href == winHref){
			$('.cntMenuPrinc ul li').removeClass('corMenuselec');
			$(this).addClass('corMenuselec');
		}
		if(escape(unescape($('#Anterior a').attr('href'))) == href){
			$(this).addClass('corMenuselec');
		}
	});
	if($('.cntMaePort li').length > 1){
		$(".cntMaePort").cycle({
			fx: "scrollHorz",
			speed: 500,
			timeout: 0,
			pause: 1,
			prev: '#prev',
			next: '#next',
			easing: 'easeInOutCubic'
		});
	}
	if($('#thumbnails li').length > 1){
		$("#thumbnails").cycle({
			fx: "scrollHorz",
			speed: 500,
			timeout: 0,
			pause: 1,
			prev: '#prev',
			next: '#next',
			easing: 'easeInOutCubic'
		});
	}
	$('#thumbnails li a').live('click', function(event){
		event.preventDefault();
		var src = $(this).attr('href');
		$('#showImg img').css({ opacity: 0 }).attr('src', src).stop().animate({ opacity: 1 }, 300);
		//$('#showImg').html('<img src="' + src + '" />').stop().animate({ opacity: 1 },300);
	});
});

