jQuery(document).ready(function(){

var objCarrosseis = Array(
	{lista:"#blocoWorks",btProx:".proximoWorks",btAnt:".anteriorWorks",btPause:"",auto:0, scrollit: 3},
	{lista:"#blocoBusca",btProx:".proximoBusca",btAnt:".anteriorBusca",btPause:"",auto:0, scrollit: 3}
/*	{lista:"#flickrCar",btProx:".proximoFlickr",btAnt:".anteriorFlickr",btPause:"",auto:0, scrollit: 5},*/
	
);
			//
			
			jQuery.each(jQuery.browser, function(i) {
			   if(jQuery.browser.msie){
			     jQuery("#ifie").addClass("bloco");
			   }
			 });
			
			//frasesrand();
			videosrand();
			
			//Substitui o campo file
			
			jQuery('#filepc').change(function() {
			 jQuery("#fakefilepc").text(jQuery("#filepc").val());
			});
			
			jQuery('#mandabem').change(function() {
			 jQuery(".select").text(jQuery("#mandabem").val());
			});
			
			
			// Bouncer animation (by Leo Xavier)
			// BASE SPEED OF BOUNCING. WILL ADD RAINDOM 0-100 TO UNSYNC BOUNCING
		//	var bouncespeed = 400;
			
			// SELECT ALL A'S EXCEPT... RESET BG-POSITION TO AVOID INITIAL POSITION BUG AND CALL BOUNCER
		//	jQuery('.reload').each(
		//		function () {
		//			jQuery(this).css({backgroundPosition: '5px 5px'});
		//			bounce(this);
		//		}
		//	);
			
			// ACTUAL BOUNCER. CALLBACK OF ANIMATION IS THE BOUNCER ITSELF, TO LOOP ALL NIGHT LONG
		//	function bounce(currentA) {
		//		newx = Math.floor(10*Math.random());
		//		newy = Math.floor(10*Math.random());
		//		newspeed = bouncespeed + Math.floor(100*Math.random());
		//		jQuery(currentA).animate({backgroundPosition: newx + 'px ' + newy + 'px'}, newspeed, 'linear', function() { bounce(currentA);});
		//	}
			
			//CRIA OS CARROSSEIS
			for (el in objCarrosseis){
				ligaCarrossel( objCarrosseis[el].lista,objCarrosseis[el].btProx,objCarrosseis[el].btAnt,objCarrosseis[el].btPause,objCarrosseis[el].auto,objCarrosseis[el].scrollit  );
			}


			jQuery("nav ul li a").click(function(){
				 jQuery(".selecionado").removeClass("selecionado");
				 jQuery(this).addClass("selecionado");
			});
			
			jQuery(".boxNav li a").click(function(){
				 jQuery(".ativado").removeClass("ativado");
				 jQuery(this).addClass("ativado");
			});
			
			jQuery(".closeWindow").click(function(){
				jQuery("#contato").slideUp('slow');
				jQuery("#prazer").slideUp('slow');
				jQuery("#quemsomos").slideUp('slow');
				jQuery("#fazemos").slideUp('slow');
				jQuery("#clientes").slideUp('slow');

			});
			
			jQuery(".contato").click(function(){
				jQuery("#contato").slideToggle('slow');
				jQuery("#prazer").slideUp('slow');
				jQuery("#quemsomos").slideUp('slow');
				jQuery("#fazemos").slideUp('slow');
				jQuery("#clientes").slideUp('slow');

			});
		
			jQuery(".cherryplus").click(function(){
				jQuery("#prazer").slideToggle('slow');
				jQuery("#contato").slideUp('slow');
				jQuery("#quemsomos").slideUp('slow');
				jQuery("#fazemos").slideUp('slow');
				jQuery("#clientes").slideUp('slow');

			});
			
			jQuery(".fazemos").click(function(){
				jQuery("#fazemos").slideToggle('slow',function(){
					
					//ligaCarrossel( "#fazemosul",".fazprox",".fazant","",0,1 );
					
				});
				jQuery("#contato").slideUp('slow');
				jQuery("#prazer").slideUp('slow');
				jQuery("#quemsomos").slideUp('slow');
				jQuery("#clientes").slideUp('slow');
			});
			
			jQuery(".equipe").click(function(){
				
				jQuery("#quemsomos").slideToggle('slow',function(){
					ligaCarrossel( "#quemsomosul",".quemprox",".quemant","",0,2 );
				});
				
				jQuery("#contato").slideUp('slow');
				jQuery("#prazer").slideUp('slow');
				jQuery("#fazemos").slideUp('slow');
				jQuery("#clientes").slideUp('slow');
			});
			
			jQuery(".clientes").click(function(){
				jQuery("#clientes").slideToggle('slow');
				jQuery("#contato").slideUp('slow');
				jQuery("#prazer").slideUp('slow');
				jQuery("#fazemos").slideUp('slow');
				jQuery("#quemsomos").slideUp('slow');
			});
});



// Função que inicia os carrosseis

function ligaCarrossel( lista, btProx, btAnt, btPause, auto, scrollit ){
				//alert(lista)
				jQuery( lista ).jcarousel({
		    		wrap: 'both',
		    		animation: 'slow',
		    		auto: auto,
		        scroll: scrollit,
		        initCallback: function (carousel, state) {
		        		jQuery( btProx ).unbind('click');
								jQuery( btProx ).bind('click', function() {
									carousel.next();
									return false;
								});
								
								jQuery( btAnt ).unbind('click');
								jQuery( btAnt ).bind('click', function() {
									carousel.prev();
									return false;
								});

								if (state == 'init') {
									carousel.startAutoOrig = carousel.startAuto;
									carousel.startAuto = function() {
									if (!carousel.paused) {
										carousel.startAutoOrig();
									}
								}

								carousel.pause = function() {
									carousel.paused = true;
									carousel.stopAuto();
								};

								carousel.play = function() {
									carousel.paused = false;
									carousel.startAuto();
								};
								var lblpause = btPause;
								jQuery( btPause ).click(function() {
									if(carousel.paused){
											jQuery( lblpause ).toggleClass('play');
											carousel.play();
										}else{
											jQuery( lblpause ).toggleClass('play');
											carousel.pause();
									}

								});

								}

								carousel.play();

								},
		        buttonNextHTML: null,
		        buttonPrevHTML: null
		    });

}

//Função para mostrar e esconder o share

function mostrashare(aa,bb){
	    jQuery(bb).addClass("bloco");
};

function escondeshare(aa,bb){
	    jQuery(bb).removeClass("bloco");
};

// Função que faz o filtro de works

function filtra(opcao, aa){
	jQuery('.current').removeClass('current');
	jQuery(aa).addClass('current');
	
	//jQuery('#worksblock').html('<span class="loading"><img src="http://192.168.1.254/phpserver/wordpress/cherryplus/wp-content/themes/cherryplus/img/loading.gif"/></span>');			
	jQuery('#worksblock').load(siteurl + '/filtro/',{f:opcao},function(){
		
		ligaCarrossel( "#blocoWorks",".proximoWorks",".anteriorWorks","",0 );
			
	});
	
}

function filtraworks(opcao, aa){
	jQuery('.current').removeClass('current');
	jQuery(aa).addClass('current');
	
	//jQuery('#worksblockInterna').html('<span class="loading"><img src="http://192.168.1.254/phpserver/wordpress/cherryplus/wp-content/themes/cherryplus/img/loading.gif"/></span>');			
	jQuery('#worksblockInterna').load(siteurl + '/filtroworks/',{f:opcao},function(){
		
		ligaCarrossel( "#blocoWorks",".proximoWorks",".anteriorWorks","",0 );
			
	});
	
}

// Função que faz as frases randomicas da home

//function frasesrand(){

//var randscript = parseInt(Math.random()*(4));

//var frases = new Array(4)

//frases[0]="Internet é o pequeno grande mundo que a gente constrói todo dia, com paixão, conhecimento, criatividade, design e tecnologia."

//frases[1]="Os consumidores já levaram sua marca para as redes sociais. Nosso papel é ajudar você a entender esse canal de comunicação e utilizá-lo da melhor forma."

//frases[2]="Nosso talento é transformar em negócio a presença digital da sua marca."

//frases[3]="Nosso desafio é utilizar a internet como uma plataforma convergente para a comunicação da sua marca."

//jQuery("#textCherry").html("<p>" + frases[randscript] + "<p>"); 

//}

//Função que faz o video da home randomico

function videosrand(){

//var randscript = parseInt(Math.random()*(2));

var randscript = 0;

var videos = new Array()
		
		videos[0]='<div id="video"><iframe src="http://player.vimeo.com/video/25192127?title=0&amp;byline=0&amp;portrait=0" width="814" height="459" frameborder="0"></iframe></div>';
		
		//videos[0]='<div id="video"><object width="814" height="459"><param name="wmode" value="opaque" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=19452285&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=19452285&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="814" height="459" wmode="opaque"></embed></object></div>'
		
		//videos[1]='<div id="video"><object width="814" height="459"><param name="wmode" value="opaque" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=19446970&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=19446970&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="814" height="459" wmode="opaque"></embed></object></div>'
		
		//videos[2]='<div id="video"><object width="814" height="459"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=19441172&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=&amp;fullscreen=1&amp;autoplay=0&amp;loop=0" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=19441172&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=&amp;fullscreen=1&amp;autoplay=0&amp;loop=0" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="814" height="459"></embed></object></div>'
		

//videos[0]='<div id="video"><object width="814" height="459"><param name="wmode" value="opaque" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=11087513&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=11087513&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="814" height="459" wmode="opaque"></embed></object></div>'
		
	//	videos[1]='<div id="video"><object width="814" height="459"><param name="wmode" value="opaque" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=11088463&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=11088463&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="814" height="459" wmode="opaque"></embed></object></div>'
		
		//videos[2]='<div id="video"><object width="814" height="459"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=13913433&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=&amp;fullscreen=1&amp;autoplay=0&amp;loop=0" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=13913433&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=&amp;fullscreen=1&amp;autoplay=0&amp;loop=0" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="814" height="459"></embed></object></div>'
		
		

jQuery("#videoscherry").html("<p>" + videos[randscript] + "<p>"); 

if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) { 
	if  (document.cookie.indexOf("iphone_redirect=false") == -1)
		jQuery("#videoscherry").html('<video src="http://www.cherryplus.com.br/v3/wp-content/themes/cherryplus/img/reel.mp4" controls="controls"></video>');
	}
}


//Funções que fazem aparecer os videos de web e motion na página works depois do filtro. o_O

function videoworks(aa, bb){
	jQuery("#destaqueWorks").addClass('none');
	jQuery(aa).removeClass('bloco');
	jQuery(bb).addClass('bloco');
}

function todosdestaque(){
	jQuery("#videoweb").removeClass('bloco');
	jQuery("#videomotion").removeClass('bloco');
	jQuery("#destaqueWorks").removeClass('none');
}


jQuery('#quemsomosul').find('li').hover(onOver,onOut);
		
		
		function onOver(){
			jQuery(this).find('.foto-equipe').css('backgroundPosition', "0 -250px");
			jQuery(this).find('.foto-equipe').find('span').animate({"marginTop":'220px'}, 350);
			//jQuery(this).find('.foto-equipe').animate({backgroundPosition:"(0 -250px)"}, {duration:500});
		}
		
		
		function onOut(){
			jQuery(this).find('.foto-equipe').css('backgroundPosition', "0 0 ");
			jQuery(this).find('.foto-equipe').find('span').stop();
			jQuery(this).find('.foto-equipe').find('span').css("marginTop",'250px');
			//jQuery(this).find('.foto-equipe').animate({backgroundPosition:"(0 0)"}, {duration:500});
		}



/*
https://api.instagram.com/v1/tags/cherryplus/media/recent?access_token=1885958.f59def8.1880e956579a49748dd24585200ed276 */

/**
 * Plugin: jquery.zRSSFeed
 * 
 * Version: 1.0.1
 * (c) Copyright 2010, Zazar Ltd
 * 
 * Description: jQuery plugin for display of RSS feeds via Google Feed API
 *              (Based on original plugin jGFeed by jQuery HowTo)
 * 
 * Modified by Richard Mackney for Instagram images
 **/
(function($){

	var current = null; 
	
	$.fn.rssfeed = function(url, options) {	
	
		// Set pluign defaults
		var defaults = {
			limit: 10,
			header: false,
			titletag: 'h4',
			date: true,
			content: true,
			snippet: true,
			showerror: true,
			errormsg: '',
			key: null
		};  
		var options = $.extend(defaults, options); 
		
		// Functions
		return this.each(function(i, e) {
			var $e = $(e);
			
			// Add feed class to user div
			if (!$e.hasClass('rssFeed')) $e.addClass('rssFeed');
			
			// Check for valid url
			if(url == null) return false;

			// Create Google Feed API address
			var api = "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?&q=" + url;
			if (options.limit != null) api += "&num=" + options.limit;
			if (options.key != null) api += "&key=" + options.key;

			// Send request
			$.getJSON(api, function(data){
				
				// Check for error
				if (data.responseStatus == 200) {
	
					// Process the feeds
					_callback(e, data.responseData.feed, options);
				} else {

					// Handle error if required
					if (options.showerror)
						if (options.errormsg != '') {
							var msg = options.errormsg;
						} else {
							var msg = data.responseDetails;
						};
						$(e).html('<div class="rssError"><p>'+ msg +'</p></div>');
				};
			});				
		});
	};
	
	// Callback function to create HTML result
	var _callback = function(e, feeds, options) {
		if (!feeds) {
			return false;
		}
		var html = '';	
		var row = 'odd';	
		
		// Add header if required
		if (options.header)
			html +=	'<div class="rssHeader">' +
				'<a href="'+feeds.link+'" title="'+ feeds.description +'">'+ feeds.title +'</a>' +
				'</div>';
			
		// Add body
		html += '<div class="rssBody">' +
			'<ul>';
		
		// Add feeds
		for (var i=0; i<feeds.entries.length; i++) {
			
			// Get individual feed
			var entry = feeds.entries[i];
			
			// Format published date
			var entryDate = new Date(entry.publishedDate);
			var pubDate = entryDate.toLocaleDateString() + ' ' + entryDate.toLocaleTimeString();
			
			// Add feed row
			html += '<li class="rssRow '+row+'">' + 
				'<'+ options.titletag +'><a href="'+ entry.link +'" title="View this feed at '+ feeds.title +'">'+ entry.title +'</a></'+ options.titletag +'>'
			if (options.date) html += '<div>'+ pubDate +'</div>'
			if (options.content) {
			
				// Use feed snippet if available and optioned
				if (options.snippet && entry.contentSnippet != '') {
					var content = entry.contentSnippet;
				} else {
					var content = entry.content;
				}
				//html += '<p><a href="'+entry.link+'" title="'+ entry.title +' " target="_blank">'+ content +'</a></p>'
				html += '<p>'+ content +'</p>'
			}
			
			html += '</li>';
			
			// Alternate row classes
			if (row == 'odd') {
				row = 'even';
			} else {
				row = 'odd';
			}			
		}
		
		html += '</ul>' +
			'</div>'
		
		$(e).html(html);
		$(e).find("a").attr("target","_blank"); // change target here
	};
})(jQuery);
