// JavaScript Document


var array_centrals=new Array();
var array_centrals_bg=new Array();
var array_centrals_flyer=new Array();
var array_centrals_swf=new Array();
var array_calendario=new Array();
var msie=false;
var mobile;
$().ready(function(){
				   
	
	if((navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/Android/i) ) != null){mobile=true;$("body").addClass("mobil");}else{$("body").addClass("browser");}

	if ( $.browser.msie ) {msie=true;$("#logo_siete_over").css("display","none");}			   
	
	home_height=$(document).height();
	$("#bg1").css("height",home_height);
	
	
	$("#left_button_news").live("click",move_left);
    $("#right_button_news").live("click",move_right);
	num_news=$("#news_items_wrap > div").size();
	news_width=num_news*220;
	$('#news_items_wrap').css("width",news_width)
	
	
	if(multiflyer){$("#right_slider_btn").live("click",move_left_central);}
	if(multiflyer){$("#left_slider_btn").live("click",move_right_central);}
	$("#central_content").live("click",show_flyer);
	
	slider_time = setInterval("move_left_central()", tiempo);
	
	$('#central').live('mouseover', over_central);
	$('#bottom_news').live('mouseover', out_central);
	$('#menu_bar').live('mouseover', out_central);
 	
	$("#left_personal_btn").live("click",move_left_personal);
    $("#right_personal_btn").live("click",move_right_personal);
	
	
	
	
		
	//$('#item1').load(function() {alert('cargado');}).trigger('load');
	

	 $('#newletter_btn').live("click",newsletter_click);
	
	
	
	
		
		
	});




//////////////// SYETEYSIETE  ///////////////////////////////


	
	
    function over_siete_link(){
		if(msie){$("#logo_siete_over").css("display","block");}
		$("#logo_siete").stop();
		$("#logo_siete_over").stop();
		$("#logo_siete_txt").css("display","block");
		$("#logo_siete").animate({"opacity":"0"},300);
		$("#logo_siete_over").animate({"opacity":"1"},300);
		
	}
	function out_siete_link(){
		if(msie){$("#logo_siete_over").css("display","none");}
		$("#logo_siete_txt").css("display","none");
		$("#logo_siete").stop();
		$("#logo_siete_over").stop();
		$("#logo_siete").animate({"opacity":"1"},300);
		$("#logo_siete_over").animate({"opacity":"0"},300);
	}
	function click_item(){
	var sUrl = "http://www.sieteysiete.com" 
	var newWindow = window.open(sUrl, '_blank');
	newWindow.focus();
	}

///////////////// LINKS ///////////////////////////////

function over_logo(par){
	
		if(msie){$("#logo_siete_over").css("display","block");}
		$(par).find($(".logo")).stop();
		$(par).find($(".logo_over")).stop();
	
		$(par).find($(".logo")).animate({"opacity":"0"},300);
		$(par).find($(".logo_over")).animate({"opacity":"1"},300);
		
	}
function out_logo(par){
		
		if(msie){$("#logo_siete_over").css("display","none");}
		$(par).find($(".logo")).stop();
		$(par).find($(".logo_over")).stop();
		$(par).find($(".logo")).animate({"opacity":"1"},300);
		$(par).find($(".logo_over")).animate({"opacity":"0"},300);
	}
	function click_logo(url){
	var sUrl = url; 
	var newWindow = window.open(sUrl, '_blank');
	newWindow.focus();
	}






function click_fb(){
	var sUrl = "http://www.facebook.com/#!/pages/Discoteca-BORA-BORA-Sabadell/145863585473669"
	var newWindow = window.open(sUrl, '_blank');
	newWindow.focus();
	}
	
	
	
	
	
	function click_yt(){
	var sUrl = "http://www.youtube.com/user/discoboratv?feature=mhee";
	var newWindow = window.open(sUrl, '_blank');
	newWindow.focus();
	}


function over_download(){
	
	$('.descargar_foto p').show();
}

function out_download(){

	$('.descargar_foto p').hide();
}



function newsletter_click () {
					re=/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/
					if(!re.exec($('#input_news').val()))    {
						alert("Direccion NO valida.");
						}else{
								$.get("consulta_newsletter.php",{'mail':$('#input_news').val(),'action':'new'},
								function(data){
								alert(data);
								$('#input_news').val("");
								});
							}
					
				}
			

//////////////// NEWS  ///////////////////////////////


 var num_news;
 var pos_x=0;
 var transition_type="easeOutCubic";

function move_left(){
	if(pos_x!=0){
	pos_x+=220;
	$("#news_items_wrap").animate({"left":pos_x},600, transition_type);
	}else{
	$("#news_items_wrap").animate({"left":20},600, function(){$("#news_items_wrap").animate({"left":0},600, transition_type);});	
	}
};
function move_right(){
	
	
	if(pos_x+$("#news_items_wrap").width()-$(".news_all_items_mask").width()>$("#news_items_mask").width()){
	pos_x-=220;
	$("#news_items_wrap").animate({"left":pos_x},600, transition_type);
	}else{
	$("#news_items_wrap").animate({"left":(pos_x-20)},600, function(){$("#news_items_wrap").animate({"left":pos_x},600, transition_type);});
	}
	
};





//////////////// CENTRAL  ///////////////////////////////


function over_central(){

	
	$('.slider_btn').fadeIn();
	
	
}

function out_central(){

	
	$('.slider_btn').fadeOut();
	
	
}




 var inex_central=0;
 var tiempo=12000;
 var slider_time="";

function move_left_central(){
	
	if( $('#'+array_centrals[inex_central]).css("left")=='0px' || $('#'+array_centrals[inex_central]).css("left")=='auto'){
	
	
	clearInterval(slider_time);
	slider_time = setInterval("move_left_central()", tiempo);
	
	var ample_item=$('#'+array_centrals[inex_central]).width();
	
	$('#'+array_centrals[inex_central]).animate({"left": -ample_item,"opacity":"0"}, 800, "easeOutCubic");
	inex_central++;
	if(inex_central>=array_centrals.length){inex_central=0}
	
	if(!mobile){
	refresh_central();
	}
	
	ample_item=$('#'+array_centrals[inex_central]).width();
	$('#'+array_centrals[inex_central]).css("display","block");
	$('#'+array_centrals[inex_central]).css("left",ample_item);
	$('#'+array_centrals[inex_central]).css("opacity","0");
	$('#'+array_centrals[inex_central]).animate({"left": "0","opacity":"1"}, 800, "easeOutCubic");
	
	}
};

function move_right_central(){
	
	if( $('#'+array_centrals[inex_central]).css("left")=='0px' || $('#'+array_centrals[inex_central]).css("left")=='auto'){
	
	
	
	clearInterval(slider_time);
	slider_time = setInterval("move_left_central()", tiempo);
	
	
		
	var ample_item=$('#'+array_centrals[inex_central]).width();
	$('#'+array_centrals[inex_central]).animate({"left": ample_item,"opacity":"0"}, 800, "easeOutCubic");
	inex_central--;
	if(inex_central<0){inex_central=(array_centrals.length-1)}
	
	if(!mobile){
	refresh_central();
	}
	
	ample_item=$('#'+array_centrals[inex_central]).width();
	$('#'+array_centrals[inex_central]).css("display","block");
	$('#'+array_centrals[inex_central]).css("left",-ample_item);
	$('#'+array_centrals[inex_central]).css("opacity","0");
	$('#'+array_centrals[inex_central]).animate({"left": "0","opacity":"1"}, 800, "easeOutCubic");
	
	}
	
};


function show_flyer(index){
	
	
	$("#yt_video").css("display","none");
	
	var intro=array_centrals_flyer[inex_central].toString();
	$.fancybox(
			{ onClosed  : function() {
				$("#yt_video").css("display","block");
				 },
	
				'overlayColor'		: '#000',
				'overlayOpacity'	: 0.86,
				'href'		: 'centrales/'+array_centrals_flyer[inex_central]
			}
		);

	
}

function refresh_central(){
	
	$('#'+array_centrals[inex_central]).html("");
	
	 var fo = new FlashObject("centrales/"+array_centrals_swf[inex_central], "main", "100%", "100%", "9", "#FFFFFF");
     fo.addParam("scale", "noscale");
     fo.addParam("menu", "false");
     fo.addParam("wmode", "transparent");
     fo.addParam("allowScriptAccess", "always");
     fo.addParam("allowfullscreen", "true");
     fo.write(array_centrals[inex_central]);	
	
}


//////////////// PERSONAL  //////////////////////////////


 
 var pos_p=0;


function move_left_personal(){
	if(pos_p!=0){
	pos_p+=275;
	$("#personal_items_wrap").animate({"left":pos_p},600, transition_type);
	}else{
	$("#personal_items_wrap").animate({"left":20},600, function(){$("#personal_items_wrap").animate({"left":0},600, transition_type);});
	}
};
function move_right_personal(){
	

	if(pos_p+$("#personal_items_wrap").width()>$("#personal_items_mask").width()){
	pos_p-=275;
	$("#personal_items_wrap").animate({"left":pos_p},600, transition_type);
	}else{
	$("#personal_items_wrap").animate({"left":(pos_p-20)},600, function(){$("#personal_items_wrap").animate({"left":pos_p},600, transition_type);});
	}
	
};



//////////////// LISTA   ///////////////////////////////////



		 
		 
function shout(texto){
	
	$.fancybox(
			'<p style="color: white;font-size:12px;padding: 10px;text-align: left;	font-family:Arial, Helvetica, sans-serif;">'+texto+'</p>',
			{ onClosed  : function() {
							$('.compartir_twitter_foto').css('display','block');	
				            $('.compartir_facebook_foto').css('display','block');	
				            $('.descargar_foto').css('display','block');
				 },
	
				'autoDimensions'	: false,
				'width'         		: '50%',
				'height'        		: 250,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			}
		);
}

function ini_web(){
	
		$('.compartir_twitter_foto').css('display','block');	
		$('.compartir_facebook_foto').css('display','block');	
		$('.descargar_foto').css('display','block');
		$('#jquery_jplayer_2').jPlayer("play");

	
}

function ini_flyer(){
	
	$('.compartir_twitter_foto').css('display','none');	
	$('.compartir_facebook_foto').css('display','none');	
	$('.descargar_foto').css('display','none');	
	
	$.fancybox({
            'transitionIn': 'elastic',
            'transitionOut': 'elastic',
            'href': 'intro_flyer.jpg'
        },
			{ onClosed  : function() {
							$('.compartir_twitter_foto').css('display','block');	
				            $('.compartir_facebook_foto').css('display','block');	
				            $('.descargar_foto').css('display','block');
							$('#jquery_jplayer_2').jPlayer("play");
				 },
	
				'autoDimensions'	: false,
				'width'         		: '50%',
				'height'        		: 250,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			}
		);
	
	
	
}

function ini_video(){
	
	
	
	
	$('.compartir_twitter_foto').css('display','none');	
	$('.compartir_facebook_foto').css('display','none');	
	$('.descargar_foto').css('display','none');	
	
	var video_var = "http://www.youtube.com/watch?v=evAO2tDOb8M";
	
	  $.fancybox({
				   onClosed  : function() {$('.compartir_twitter_foto').css('display','block');	
				            $('.compartir_facebook_foto').css('display','block');	
				            $('.descargar_foto').css('display','block');
							$('#jquery_jplayer_2').jPlayer("play");
							},
                  'padding'             : 0,
                  'autoScale'   : false,
                  'width'               : 680,
                  'height'              : 495,
                  'href'                : 'http://vimeo.com/moogaloop.swf?clip_id=34015979',    
                  'type'                : 'swf',    // <--add a comma here 
                  'swf'                 : {'wmode':'transparent','allowfullscreen':'true'} // <-- flashvars here
                  });

	
fancybox({
                    'titleShow'     : false,
                    'transitionIn'  : 'elastic',
                    'transitionOut' : 'elastic',
            'href' : video_var.replace(new RegExp("watch\\?v=", "i"), 'v/'),
            'type'      : 'swf',
            'swf'       : {'wmode':'transparent','allowfullscreen':'true'}
        });

	
}

function ini_video_youtuve(video_var){
	
	
	
	
	$('.compartir_twitter_foto').css('display','none');	
	$('.compartir_facebook_foto').css('display','none');	
	$('.descargar_foto').css('display','none');	
	
	
	
	  $.fancybox({
				   onClosed  : function() {$('.compartir_twitter_foto').css('display','block');	
				            $('.compartir_facebook_foto').css('display','block');	
				            $('.descargar_foto').css('display','block');
							$('#jquery_jplayer_2').jPlayer("play");
							},
                  'padding'             : 0,
                  'autoScale'   : false,
                  'width'               : 680,
                  'height'              : 495,
                  'href'                : video_var.replace(new RegExp("watch\\?v=", "i"), 'v/'),    
                  'type'                : 'swf',    // <--add a comma here 
                  'swf'                 : {'wmode':'transparent','allowfullscreen':'true'} // <-- flashvars here
                  });
}


/////////////////////// CALENDARIO   //////////////////////////////

var current_page=0;
var calnedario_actiu=false;

var inici_calendar=true;
function display_flyer(img,par){
	 current_pic=img;
	 $('#flyer_screen').html("");
	 $('#flyer_screen').hide();
	 if(inici_calendar){inici_calendar=false;}else{$('#lista_fechas ul li').removeClass('activo');}
		$(par).addClass('activo');
	    $('#loading_flyer').show();
		var url=new String();
		url="centrales/"+img;
	    
        var img = new Image();
        $(img).load(function () {
			$('#flyer_screen').show();
			$(this).hide();
			$('#loading_flyer').hide();
            $('#flyer_screen').append(this);
			$(this).css("visivility","hidden");
			$(this).css("display","block");
			
			/////// resizing  ///////
			var nou_alt=575;
			var nou_ample=400;
			var ample=$('#flyer_screen img').width();
			var alt= $('#flyer_screen img').height();
			
			if(alt>=ample){
				nou_ample=nou_alt*ample/alt;
				$('#flyer_screen img').css("height",nou_alt+"px");
				$('#flyer_screen img').css("width",nou_ample+"px");
			}else{
				nou_alt=nou_ample*alt/ample;
				$('#flyer_screen img').css("width",nou_ample+"px");
				$('#flyer_screen img').css("height",nou_alt+"px");
			}
			////// fin resizing //////
			
			$(this).css("display","none");
			$(this).css("visivility","visible");
			
            $(this).fadeIn();
        }).error(function () {
            // alert("error");
        }).attr('src', url);
   
	
}

function load_page(indice){
	
	$.ajax({
			  type:'POST',
			  url: 'calendario_web.php?page='+indice,
			  context: document.body,
			  success: function(data) {
				$('#calendario_mc').html(data);
				
				
				
			}
		});
	
}


$(window).scroll(function() {
				
			if(calnedario_actiu){
				
					var altura =$(window).scrollTop()-200;
					
					if(altura>21 && altura<604){
					$("#flyer_wrap").stop().animate({"margin-top": altura},600);
					}
					
					if(altura<21){
						$("#flyer_wrap").stop().animate({"margin-top": 28},600);
					}
					
					if(altura>604){
						$("#flyer_wrap").stop().animate({"margin-top": 600},600);
					}
				
			}
				
     });
			
/////////////////////// REPORTEROS   //////////////////////////////

function load_repor(indice,filtro){
	
	var _indice=indice;
	var _filtro=filtro;
	
	$.ajax({
			  type:'POST',
			  url: 'reportajes_web.php?page='+_indice+'&filtro='+_filtro,
			  context: document.body,
			  success: function(data) {
				$('#reportajes_mc').html(data);
				
			}
		});
	
}


/////////////////////// FAMOSOS   //////////////////////////////

function vota(_id){
	
	var id=_id;
	
	
	$.ajax({
			  type:'POST',
			  url: 'votar_web.php?id='+id,
			  context: document.body,
			  success: function(data) {
				$('#'+id+'_voto').fadeOut();
				alert(data)
				
			}
		});
}
