picnAlbum = '265235100216902';
picnEvent = '244415398979779';
picnVideosArray = ['nzxYUsnZV6M', 'jlbn364BH-o', 'MejbOFk7H6c','nHlJODYBLKs', '2uRrdeUiqCA','KlnLuUy5IEE','NEXR9tFeAQk','X_bFO1SNRZg','ntA7NdgB4qA','CBGSTEmgvtE','r-kHIsPe-Qw','Rska-Z3oDtY','GbaMmRBANr8','rA6keIuRjKM','rY8Y3o31k1M','CBGSTEmgvtE', 'jlbn364BH-o', 'MejbOFk7H6c', 's3Tl6-3e2MQ', 'cObdw2yyBug'];
picnVideo = picnVideosArray[Math.floor(Math.random()*picnVideosArray.length)];

overAlbum = '10150563826896186';
overEvent = '237284976365209';
overVideosArray = ['E-TvqSmTEmk', '2sDXv5FcInQ', 'd7enG9nTjMo','NbU-_sYA4X4','EgrP6fzGKjg','UuzLV2J664s','pZ3cTwI9bIw','4HWcViTXdYc','puu3IvKnSb4','YUURBYFn9Z8','YhetpGY9gYA','UjiswvTXdzA', 'KnBi-LNM0Og', 'RNc45FTenhg', 'CreEuaS8QY'];
overVideo = overVideosArray[Math.floor(Math.random()*overVideosArray.length)];

mainVideosArray = picnVideosArray.concat(overVideosArray);
mainVideo = mainVideosArray[Math.floor(Math.random()*mainVideosArray.length)];

extra = false;
extraAlbum = '265235100216902';
extraEvent = '187108934728450';
extraVideosArray = ['nHlJODYBLKs', '2uRrdeUiqCA','KlnLuUy5IEE','NEXR9tFeAQk', 'X_bFO1SNRZg', 'ntA7NdgB4qA', 'CBGSTEmgvtE', 'r-kHIsPe-Qw', 'Rska-Z3oDtY', 'GbaMmRBANr8', 'rA6keIuRjKM', 'rY8Y3o31k1M', 'CBGSTEmgvtE'];
extraVideo = mainVideosArray[Math.floor(Math.random()*mainVideosArray.length)];

/* Author: 	

*/

animationSpeed = 1200;

if($(window).width() < 768){
	isSmallScreen = true;
	$('body').addClass('isSmallScreen');
	offsetPadding = (0.075*$(window).height())-63;
}
else{
	isSmallScreen = false;
	offsetPadding = 0.075*$(window).height();
}




/* does not work on fb
var loc = new String(window.parent.document.location);
if (loc.indexOf("https://")!= -1){
	ssl = true;
}
else{
	ssl = false;
}
*/
ssl = true;

UTILS = {
	externalLinks : function(){
		var baseAddress = window.location.hostname;
		$("a[href^='http:']").not("[href*='"+baseAddress+"']").on('click', function(){
			window.open(this.href); return false;
		})
	}
};

ALLEYVERAO = {
	menu : {
		init : function(){
			$('footer header a').click(function(){
				ALLEYVERAO.menu.festas( $(this).attr('rel') );
				_gaq.push(['_trackEvent', 'internalLink', 'click', $(this).attr('rel')]);
				return false;
			});
			$('footer .main a').click(function(){
				ALLEYVERAO.menu.etc( $(this).index() );
				_gaq.push(['_trackEvent', 'internalLink', 'click', $(this).text()]);
				return false;
			})
		},
		festas : function(name){
			if(name == 'home'){
				$('html,body').animate({scrollTop: 0}, animationSpeed, 'easeOutCubic');
				_gaq.push(['_trackEvent', 'internalLink', 'click', name]);
			}
			else{
				$('html,body').animate({scrollTop: $("#"+name).offset().top + offsetPadding}, animationSpeed, 'easeOutCubic');
				_gaq.push(['_trackEvent', 'internalLink', 'click', name]);
			}
		},
		etc : function(target){
			if(isSmallScreen != true){
				$('html,body').animate({scrollTop: $("#etc").offset().top + offsetPadding}, animationSpeed, 'easeOutCubic');
				$('#etc .container').animate({left: -target * 100 + '%'},animationSpeed, 'easeOutCubic');	
			}
			else{
				$('html,body').animate({scrollTop: $("#etc").offset().top - 10}, animationSpeed, 'easeOutCubic');
			}
		},
		homeBoxes : function(){
			$('#home .chamadaFesta').css({cursor:'pointer'}).on('click',function(){
				if( $(this).hasClass('picnic') ){
					$('html,body').animate({scrollTop: $("#picnic").offset().top + offsetPadding}, animationSpeed, 'easeOutCubic');
				}
				else if( $(this).hasClass('od') ){
					$('html,body').animate({scrollTop: $("#overdancing").offset().top + offsetPadding}, animationSpeed, 'easeOutCubic');
				}
				else if( $(this).hasClass('extra') ){
					$('html,body').animate({scrollTop: $("#extra").offset().top + offsetPadding}, animationSpeed, 'easeOutCubic');
				}
			})
		}
	},//end menu

	fbPhotos : function(target, fbAlbumId, isHome){
		fbAlbumId = (typeof fbAlbumId == 'undefined') ? '236205663119846' : fbAlbumId;
		
		if(isHome == true){
			fbAlbumId = Math.round(Math.random(0,1)) == 0 ? picnAlbum : overAlbum;
		}

		
		var limit = isHome ? 12 : 4;

		var url = ssl ? "https://graph.facebook.com/" + fbAlbumId + "/photos&callback=?&limit="+limit+"&return_ssl_resources=1" : "https://graph.facebook.com/" + fbAlbumId + "/photos&callback=?&limit="+limit;
				
		$.getJSON(url, function(json) {
			
			var html = "";
			if(!isHome){
				$.each(json.data, function(i, fb) {
					if(i <= limit) {
						if(i == 2){
							var name = "";
							if(fb.name !== undefined){var name = fb.name;}
							var randomAlley = Math.floor(Math.random()*6)+1;
							html += "<img src=\"img/image.php?src=alleyverao-"+ randomAlley +".jpg&amp;w=210&amp;h=300\" title=\"Verão Intenso no Alley\" alt=\"Verão Intenso no Alley\" />";
							html += "<img src=" + fb.images[1].source + " title=\"Alley\" alt=\"Alley\" />";	
						}
						else{
							var name = "";
							if(fb.name !== undefined){var name = fb.name;}
							html += "<img src=" + fb.images[1].source + " title=\"Alley\" alt=\"Alley\" />";	
						}
					}//end if
				});//end $.each
			}
			else{
				$.each(json.data, function(i, fb) {
					if(i <= limit && i >= limit/2) {
						var name = "";
						if(fb.name !== undefined){var name = fb.name;}
						html += "<img src=" + fb.images[1].source + " title=\"Alley\" alt=\"Alley\" />";	
					}//end if
				});//end $.each
			}

			html += "";
			target
				.html(html);
			
			if($.browser.msie){
				target.columnize({columns:3, ignoreImageLoading: false});
			}


				
		});//end $.getJSON
			
	},//end fbPhotos
	
	fbEvent : function(target, fbEventId){
		if(typeof fbEventId != 'undefined'){
			target= (typeof target == 'undefined') ? $('#picnic') : target;

			// get basic event info
			if(ssl == true){
				var url = "https://graph.facebook.com/" + fbEventId + "/?metadata=1&return_ssl_resources=1&callback=?";
			}
			else{
				var url = "https://graph.facebook.com/" + fbEventId + "/?metadata=1&callback=?";
			}

			/*
			$.getJSON(url, function(json) {
				theName = json.name;
				theDescription = json.description;
				theDescription = theDescription.split('\nAlley Club')[0].replace(/\n/g,"<br />");
				if(ssl == true){
					theImage = '<img src="https://graph.facebook.com/'+fbEventId+'/picture/?type=large&return_ssl_resources=1" alt=" " />';
				}
				else{
					theImage = '<img src="https://graph.facebook.com/'+fbEventId+'/picture/?type=large" alt=" " />';
				}
				if(!isSmallScreen){
					target.find('.chamadaFesta').prepend(theImage);
				}
				target.find('.event-text').html(theDescription); 
			});//end $.getJSON
			*/
			// get attending
			var access_token = '103321699787783|746154ee66adf8b6f0bc2d14659e5be7';
			if(ssl == true){
				var url = "https://graph.facebook.com/" + fbEventId + "/attending/?access_token=" + access_token + "&limit=16return_ssl_resources=1&callback=?";	
			}
			else{
				var url = "https://graph.facebook.com/" + fbEventId + "/attending/?access_token=" + access_token + "&limit=16&callback=?";
			}
			$.getJSON(url, function(json) {
				var html = "";
				html += "<div class=\"fb-event-link\"><a href=\"http://facebook.com/events/"+fbEventId+"\" target=\"_blank\"><span></span>veja no facebook</a></div>";
				$.each(json.data, function(i, fb){
					if(i<20){
						theId = fb.id;
						theName = fb.name;
						if(ssl == true){
							html += "<img src=\"https://graph.facebook.com/"+theId+"/picture?return_ssl_resources=1\" alt=\""+theName+"\" title=\""+theName+"\" rel=\""+theId+"\" width=\"30\" height=\"30\" />";
						}
						else{
							html += "<img src=\"https://graph.facebook.com/"+theId+"/picture\" title=\""+theName+"\" alt=\""+theName+"\" rel=\""+theId+"\" width=\"30\" height=\"30\" />";
						}					
					}
				});
				target.find('.fb-event').html(html);
			});//end $.getJSON
			/*
			$('.fb-event').on('click','img', function(){
				window.open( $(this).parent().find('a').attr('href') );
				return false;
			})
			*/	
		}//end if
	},//end fbEvent

	setJS : function(){
		$('.jsonly').css({display:'block'});
	},//setJS

	eventoSlider : function(){
		$('#evento-slider-wrapper').html('<img src="img/image.php?src=eventos1-alley.jpg&amp;w=640&amp;h=320" alt=" " /><img src="img/image.php?src=eventos2-alley.jpg&amp;w=640&amp;h=320" alt=" " /><img src="img/image.php?src=eventos3-alley.jpg&amp;w=640&amp;h=320" alt=" " />')
		$('#evento-slider div.controls div').click(function(){
			var currentOffset = $('#evento-slider-wrapper').css('left');
			currentOffset = currentOffset.substring(0, currentOffset.length-1);
			if($(this).attr('id') == 'evento-slider-next'){
				if(currentOffset != -200 && currentOffset != -201 && currentOffset != -199){
					var targetOffset = parseInt(currentOffset,10)-100;
				}
				else{
					var targetOffset = 0;
				}
				$('#evento-slider-wrapper').animate({left: targetOffset + '%'},300,'easeOutCubic');
			}
			else if($(this).attr('id') == 'evento-slider-prev'){
				if(currentOffset != 0 && currentOffset != -1 && currentOffset != 1){
					var targetOffset = parseInt(currentOffset,10)+100;
				}
				else{
					var targetOffset = -200;
				}
				$('#evento-slider-wrapper').animate({left: targetOffset + '%'},300,'easeOutCubic');
			}
		})
	},

	gMaps : function(){
		$('#gmap_canvas').html('<a target="_blank" href="http://maps.google.com/maps?q=Alley+Club+-+R.+Barra+Funda,+1066+-+Santa+Cec%C3%ADlia,+Sao+Paulo+-+S%C3%A3o+Paulo,+Brasil&hl=pt-br&ie=UTF8&ll=-23.524821,-46.659944&spn=0.011785,0.01811&sll=37.0625,-95.677068&sspn=41.546728,74.179688&vpsrc=0&hq=Alley+Club+-&hnear=R.+Barra+Funda,+1066+-+Santa+Cec%C3%ADlia,+S%C3%A3o+Paulo,+01152-000,+Brazil&t=m&z=16&iwloc=A"><img src="img/gmap.png" alt="Alley Club, Rua Barra Funda 1066, São Paulo" style="max-width:100%; width:100%;" /></a>');
	},//end gMaps

	programacaoFoto : function(){
		$('#programacaoFoto').html('<img src="img/image.php?src=programacao1.jpg&amp;w=640&amp;h=320" style="width:100%; margin-bottom:16px;" alt=" " />');
	}

	
      

};//end ALLEYVERAO


DEV = {
	browserWidth : function(){
		$('<div id="UTIL_browserWidth" style="position:fixed; top:0; left:0; font-size:12px; color:#333; opacity:0.5;"></div>').prependTo('body').html($(window).width());
		$(window).resize(function(){
			$('#UTIL_browserWidth').html($(window).width());
		})

	}
};


jQuery(function($){

	if($.browser.msie){
		jQuery.fx.interval = 39;	
	}

	if(!$.browser.msie){
		likeboxWidth = $('#fb-like').width()-10;
		$('#fb-like-wrapper').html('<fb:fan profile_id="150997251185" href="http://www.facebook.com/alleyclub" width="'+likeboxWidth+'" height="70" show_faces="true" stream="false" header="false" css="http://alleyclub.com.br/verao/css/fb-likebox.css"></fb:fan>');
	}	

	ALLEYVERAO.setJS();
	ALLEYVERAO.menu.init();
	ALLEYVERAO.menu.homeBoxes();
	
	UTILS.externalLinks();

	setTimeout("ALLEYVERAO.programacaoFoto()",5000);

	setTimeout("ALLEYVERAO.fbPhotos($('.photos').eq(0), undefined, true)",2000);
	setTimeout("ALLEYVERAO.fbPhotos($('.photos').eq(1), "+picnAlbum+")",4000);
	setTimeout("ALLEYVERAO.fbPhotos($('.photos').eq(2), "+overAlbum+")",6000);
	if(extra == true){
		setTimeout("ALLEYVERAO.fbPhotos($('.photos').eq(3), "+extraAlbum+")",6000);
	}

	if(picnEvent != ''){
		setTimeout("ALLEYVERAO.fbEvent($('#picnic'), "+picnEvent+");",8000);
	}
	
	if(overEvent != ''){
		setTimeout("ALLEYVERAO.fbEvent($('#overdancing'), "+overEvent+");",10000);
	}
	
	if(extra == true && extraEvent != ''){
		setTimeout("ALLEYVERAO.fbEvent($('#extra'), "+extraEvent+");",10000);
	}
	
	setTimeout("ALLEYVERAO.gMaps();",8000);

	setTimeout("ALLEYVERAO.eventoSlider()",12000);

	if($('body').hasClass('dev')){
		DEV.browserWidth();
	}
	
	

});//end Jquery


	//youtube
	function loadYoutube(){
		var tag = document.createElement('script');
    	tag.src = "//www.youtube.com/player_api";
    	var firstScriptTag = document.getElementsByTagName('script')[0];
    	firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
	}

	setTimeout(function(){loadYoutube();},2600);

      // 3. This function creates an <iframe> (and YouTube player)
      //    after the API code downloads.
      var mainPlayer;
      var picnPlayer;
      var overPlayer;
      function onYouTubePlayerAPIReady() {
        mainPlayer = new YT.Player('mainPlayer', {
          videoId: mainVideo,
          playerVars: {
	        	'wmode': 'opaque',
	      		'autohide': 1,
	      		'rel': 0,
	      		'theme': 'light',
	      		'modestbranding': 1
	      	},
          events: {
            'onStateChange': onPlayerStateChange
          }
      })

          picnPlayer = new YT.Player('picnPlayer', {
          videoId: picnVideo,
          playerVars: {
	        	'wmode': 'opaque',
	      		'autohide': 1,
	      		'rel': 0,
	      		'theme': 'light',
	      		'modestbranding': 1
	      	},
          events: {
            'onStateChange': onPlayerStateChange
          }

      });

          overPlayer = new YT.Player('overPlayer', {
          videoId: overVideo,
          playerVars: {
	        	'wmode': 'opaque',
	      		'autohide': 1,
	      		'rel': 0,
	      		'theme': 'light',
	      		'modestbranding': 1
	      	},
          events: {
            'onStateChange': onPlayerStateChange
          }
      });
        
      if(extra == true){
	      extraPlayer = new YT.Player('extraPlayer', {
	          videoId: extraVideo,
	          playerVars: {
		        	'wmode': 'opaque',
		      		'autohide': 1,
		      		'rel': 0,
		      		'theme': 'light',
		      		'modestbranding': 1
		      	},
	          events: {
	            'onStateChange': onPlayerStateChange
	          }
	      });	
      }

      


      }

     // 4. The API will call this function when the video player is ready.
      function onPlayerReady(event) {
      	
      }

      // 5. The API calls this function when the player's state changes.
      function onPlayerStateChange(event) {
        if (event.data == YT.PlayerState.PLAYING){
        	
        	if(event.target.id == 1){
        		picnPlayer.stopVideo();
        		overPlayer.stopVideo();
        		if(extra == true){
        			extraPlayer.stopVideo();
        		}
        		$('#mainPlayer').parent().parent().animate({width:'100%'},600, function(){
	        		setTimeout(function(){mainPlayer.playVideo();},500)
	        	});
        	}

        	else if(event.target.id == 2){
        		mainPlayer.stopVideo();
        		overPlayer.stopVideo();
        		if(extra == true){
        			extraPlayer.stopVideo();
        		}
        		$('#picnPlayer').parent().parent().animate({width:'100%'},600, function(){
        			setTimeout(function(){picnPlayer.playVideo();},500);
        		});
        	}

        	else if(event.target.id == 3){
        		mainPlayer.stopVideo();
        		picnPlayer.stopVideo();
        		if(extra == true){
        			extraPlayer.stopVideo();
        		}
        		$('#overPlayer').parent().parent().animate({width:'100%'},600, function(){
        			setTimeout(function(){overPlayer.playVideo();},500);
        		});
        	}
        	
        	else if(event.target.id == 4){
        		mainPlayer.stopVideo();
        		picnPlayer.stopVideo();
        		overPlayer.stopVideo();
        		$('#extraPlayer').parent().parent().animate({width:'100%'},600, function(){
        			setTimeout(function(){extraPlayer.playVideo();},500);
        		});
        	}

        }

      }

