


var page=1;



//vertical align a tweet
function centerTwitter(){
	var ah = $("#tweet").height();
	var ph = $("#twitter").height() - 60;
	var mh = (ph - ah) / 2;
	$("#tweet").css('margin-top', mh);
	//$("#bird").hide();
}

function setupFlickrBadge(){

	//$("#badge").hide();
	//$(".flickr_badge_image").hide();
	
	flickrHTML="";
	$("#badge-fake img").each(function(){
		
		t = $(this);
		var img = t.attr('src');
		img = img.replace("_m.jpg","_s.jpg");
	 	large = 	img.replace("_s.jpg",".jpg");

		if(img.slice(-3)=="jpg"){
			flickrHTML += '<div class="badgeImage"> <a href="'+large+'" class="zoom" rel="pico"><img src="'+img+'" /></a> </div>';
		}
	});
	
	$("#badge").html(flickrHTML);
	
	$('.badgeImage').css('cursor','pointer');
	

	
	$('.badgeImage').hover(function(){
		$(this).css('opacity','.7');
	 },function() {
	    $(this).css('opacity','1');
	 });
	
	$("a.zoom").fancybox();
	
}

var _video_on =false;

function getVideo(id){

	useID = $("#video_"+id).attr('rel');
	
	if((useID==video_id) && (_video_on)){
		
	}else{
		//set new moogaloop
		video_id = useID;
	
		if(_video_on){
			embedVideo(true);
		}else{
			embedVideo(true);
		}
		playVideo();
	}
}

function playVideo(){
		videoON();
		var me = moogaloop.api_play();
	
}
function videoON(){
		$("#nav").css('display','none');
		lightsON();
		_video_on=true;
		$("#preroll").hide();
		$("#vimeo").show();
		//TODO - update the roll-title for after 
}
function videoOFF(){
		lightsOUT();
		_video_on=false;
		$("#preroll").show();
		$("#vimeo").hide();
}
function preRollClick(){
	getVideo(videoID)
}

function lightsOUT(){
	$("#featured-overlay").fadeOut();
	$("#nav").css('display','block');
	if(_video_on){
		moogaloop.api_pause();
	}

}
function lightsON(){
	$("#featured-overlay").fadeIn();
}


var setupMe = false;
function setupVideoButton(){
	
	if(setupMe==false){
		
		$("#featured-overlay").click(function(){
			lightsOUT();
		});
		
		preRollTitle();
		setupMe=true;
		$("#vimeo").hide();
		//$("#preroll").fadeIn();

		$("#preroll").css('cursor','pointer');
		$("#preroll").click(function(){
			preRollClick();
		});
	}
	
}

function preRollTitle(){
	var texter = $("#video_"+videoID+" a").html();
	var theString = 'Click to play : <span class="titleText">'+texter+'</span>';
	document.getElementById('roll-title').innerHTML = theString;
//	var me = $("#roll-title").html();
}


/*
	Subscribing to fan bridge


*/
function submitSubscribe(){
	

	zip = $("#iZip").val();
	email= $("#iEmail").val();
	form_ok=true;
	if((email==undefined) || (email=='')){
		form_ok=false;
	}
	if((zip==undefined) || (zip=='')){
		form_ok=false;
	}
	
	
	if(form_ok){
		 useData = {
			'subscriber_id':'0',
			'apply':'yes',
			'userid':'12538',
			'email':email,
			'zip':zip
		};
		
		$.ajax({
		    type: "POST",
			data: "email="+email+"&zip="+zip+"&apply=yes&userid=12538",
		    url: "http://pico.fanbridge.com/",
		    success: function(msg){
			//	alert(msg);
		    },
			error: function(msg,date){
				alert(date);
		    }
		 });
		alert('huj?');
		
	}else{
		alert('Please Enter All Fields!');
	}
}




function setupArtistData(){
	return false;
}




$(document).ready(function(){
	 //vertical align the twitter
	 centerTwitter();
	 
	
	 //$("#preroll").hide();
	//$("#vimeo").hide();
	//$(document).pngFix();
	
//	setupArtistData();
	
	/*
	$('#subutton').click(function(){
		submitSubscribe();
	});
	*/
		
	$('.tri-item').each(function(){
		if($(this).hasClass('inactive')){
			var getA = $(".tri-item-title a",this).html();
			$("a",this).remove();
			$(".tri-item-title",this).html(getA);
			$(".tritop",this).css('top','-180px');
		}else{
			$(this).css('cursor','pointer');
		}
	});
	
	$('.tri-item').click(function(){
		var vs = $(this).attr('id');
		var vi = vs.substr(-1);
		if(!$(this).hasClass('inactive')){
			getVideo(vi);
		}
	});
	
	$('.tri-item').hover(function(div){
		if(!$(this).hasClass('inactive')){
			$(".tritop",this).css('top','-90px');
		} 
	 },function() {
		if(!$(this).hasClass('inactive')){
			$(".tritop",this).css('top','0px');
		}
	 });

		
		//setup icon hovers
	 $('#bird').hover(function(){
		$("#bird img").attr('src','_img/icon_twitter_on.jpg');	  
	 },function() {
		$("#bird img").attr('src','_img/icon_twitter.jpg');
	 });
	
	$('#adlogo').hover(function(){
		$("#adlogo img").attr('src','_img/icon_artistdata_on.jpg');	  
	 },function() {
		$("#adlogo img").attr('src','_img/icon_artistdata.jpg');
	 });
	
	$('#flickr-logo').hover(function(){
		$("#flickr-logo img").attr('src','_img/icon_flickr_on.jpg');	  
	 },function() {
		$("#flickr-logo img").attr('src','_img/icon_flickr.jpg');
	 });
	
	
	//setupFlickr Badge
	setupFlickrBadge();
	
	
});


