$(document).ready(function(){

	$(".lightbox").lightbox({
		fitToScreen: true,
		imageClickClose: true
	});

	$(".lightbox-2").lightbox({
		fitToScreen: true
	});

	$('.scroll-pane').jScrollPane({showArrows:true});
	
	$("#buy_links_list a.close").click( function() {
		$("#buy_links_list").slideUp("slow");
		return false;
	});
	
	$('a.outbound').each(function() {
	  var $a = $(this);
	  var href = $a.attr('href');
	  // see if the link is external
	  if ( (href.match(/^http/)) && (! href.match(document.domain)) ) {
	    // if so, add the GA tracking code
	    $a.click(function() {
	      pageTracker._trackPageview('/outbound/' + href);
	    });
	  }
	  
	});
	
});

function getPhoto(p_id, section) 
{
	photos_id = p_id;
	
	$('#photo_content').html('<div style="margin: 0px auto; padding: 160px; width: 20px;"><img height="16" width="16" border="0" src="./images/loading.gif"/><\/div>');
	
	$.ajax({
		url: './photo_content.php',
		type: 'GET',
		data: {photos_id:photos_id, section:section},
		dataType: 'json',
		timeout: 8000,
		success: success_photos
	});
	
	return false;
}

function success_photos(json) 
{ 
	if (json.error) {
		// alert(json.html);
	} else {
		$('#photo_content').html(json.html);		
	}
	setTimeout('initBinding();',100);
	return false;
} 

function success_events(json) 
{ 
	if (json.error) {
		alert(json.html);
	} else {
		$('#event_detail').html(json.html);		
	}
	setTimeout('initBinding();',100);
	return false;
} 

function initBinding() 
{
	$(".lightbox").lightbox({
		fitToScreen: true,
		imageClickClose: false
	});	

}

function toggle_tabs(show_tab,hide_tab)
{
	
	if (show_tab == '#photos' || show_tab == '#reviews') {
		
		
		if (show_tab == "#reviews") {
		//	$("#reviews_scroll.scroll-pane").width("773px");
			$("#reviews_wrapper h3").html("REVIEWS FROM THE CRITICS");
		}	
		
		$('div#norman_bklnks').removeClass('yello');
		$('div#norman_bklnks h4 img:first').attr('src','/images/arrow_right_white.gif');
		$('div#photos_bklnks h4 img:first').attr('src','/images/arrow_down_yello.gif');
		$('div#photos_bklnks').addClass('yello');
		$('div#photos_bklnks h4').removeClass('photos_white');
		
		$('#tweets').hide();
		$('div#tweets_bklnks').removeClass('yello');
		$('div#tweets_bklnks h4 img:first').attr('src','/images/arrow_right_white.gif');
		
	
	} else if (show_tab == '#tweets') {
	
		$("#reviews_wrapper h3").html("FROM TWITTER");
		

		$('div#norman_bklnks h4 img:first').attr('src','/images/arrow_right_white.gif');
		$('div#photos_bklnks h4 img:first').attr('src','/images/arrow_right_white.gif');
		$('div#norman_bklnks').removeClass('yello');
		$('div#photos_bklnks').removeClass('yello');
		$('div#photos_bklnks h4').addClass('photos_white');
		
		// tweets
		$('div#tweets_bklnks').addClass('yello');
		$('div#tweets_bklnks h4').removeClass('photos_white');
		$('div#tweets_bklnks h4 img:first').attr('src','/images/arrow_down_yello.gif');
		
		$('#reviews').hide();
		
	
	
	} else {
		
		if (show_tab == "#news") {
		//	$("#news_scroll.scroll-pane").width("773px");
		//	$("#news_scroll.scroll-pane").height("auto");	
			$("#reviews_wrapper h3").html("NEWS");	
		}
		
		$('div#photos_bklnks h4 img:first').attr('src','/images/arrow_right_white.gif');
		$('div#photos_bklnks').removeClass('yello');
		$('div#photos_bklnks h4').addClass('photos_white');
		$('div#norman_bklnks h4 img:first').attr('src','/images/arrow_down_yello.gif');
		$('div#norman_bklnks').addClass('yello');
		
		//tweets
		$('#tweets').hide();
		$('div#tweets_bklnks').removeClass('yello');
		$('div#tweets_bklnks h4 img:first').attr('src','/images/arrow_right_white.gif');
		
		
	}

	$(show_tab).show();
	$(hide_tab).hide();	
	
	// setTimeout("$('.scroll-pane').jScrollPane({showArrows:true});",200);
	// $('.scroll-pane').jScrollPane({showArrows:true});
}

function playerReady(obj)
{
    player = gid(obj.id);
}
function gid(name)
{
    return document.getElementById(name);
}


function createPlayer(swf_file, mp3_to_play, preview_image, eq, go) 
{
	var flashvars = {
			file:mp3_to_play,
			image:preview_image,					
			autostart:go,
			showeq:false,
			id:"player1"
	}
	var params = {
			allowfullscreen:"true", 
			allowscriptaccess:"always",
			wmode:"transparent"
	}
	var attributes = {
			id:"player1",  
			name:"player1"
	}
	swfobject.embedSWF(swf_file, "swf_placeholder", "304", "234", "9.0.98", false, flashvars, params, attributes);
}						

function createAudioPlayer(file_to_play, preview_image, eq, go) 
{
	var flashvars = {
			file:file_to_play,
			image:false,					
			autostart:go,
			showeq:eq,
			id:"player2"
	}
	var params = {
			allowfullscreen:"true", 
			allowscriptaccess:"always",
			wmode:"transparent"
	}
	var attributes = {
			id:"player2",  
			name:"player2"
	}
	swfobject.embedSWF("mp3player.swf", "swf_placeholder2", "150", "20", "9.0.98", false, flashvars, params, attributes);


	/* reset audio 
	$("#audio ul li").removeClass('playing');
	swfobject.removeSWF('player2');
	$("#audio_player").html("<div id='swf_placeholder2'></div>"); 
	*/
}	
				
function play_mp3(elem, clip, preview)
{
	if( mp3_playing == elem['id']) {
		swfobject.removeSWF('player2');
		$("#audio_player").html("<div id='swf_placeholder2'></div>");
		$("#audio ul li").removeClass('playing');
		mp3_playing = null;
	} else {
		$("#audio ul li").removeClass('playing');
		$(elem).addClass('playing');
		swfobject.removeSWF('player2');
		$("#audio_player").html("<div id='swf_placeholder2'></div>");
		createAudioPlayer(clip, preview, false, true); 
		mp3_playing = elem['id'];
	}
	
	/*
	reset video
	swfobject.removeSWF('player1');
	$("#video").html("<div id='swf_placeholder'></div>");
	createPlayer(file_to_play, preview_image, false, false);
	*/
}				


//  video in a box
function showPlayer() {  
	
	document.getElementById("bodyId").style.overflow = "hidden";
	document.getElementById("head_video_matte").style.width = 100+"%";
	document.getElementById("head_video_matte").style.height = 100+"%"; 
	document.getElementById("head_video_wrapper").style.top = 175+"px";
	document.getElementById("home_review").innerHTML = "<div id='quotes' name='intro' width='643' height='207'></div>";
}

function hidePlayer() { 
	// player.sendEvent('STOP');
	document.getElementById("head_video_wrapper").innerHTML = "<div id='swf_placeholder'></div>";
	document.getElementById("bodyId").style.overflow = "auto"; 
	document.getElementById("head_video_matte").style.width = 0+"%";
	document.getElementById("head_video_matte").style.height = 0+"%";
	document.getElementById("head_video_wrapper").style.top = -9999+"px";
	swfobject.embedSWF('CFTS_homequotes_01.swf', 'quotes', '643px', '207px', '9.0.98');
}

function createPlayer_head(swf_file, mp3_to_play, preview_image, eq, go) 
{
	var flashvars = {
			file:mp3_to_play,
			image:preview_image,					
			autostart:go,
			showeq:false,
			id:"player1"
	}
	var params = {
			allowfullscreen:"true", 
			allowscriptaccess:"always"
	}
	var attributes = {
			id:"player1",  
			name:"player1"
	}
	swfobject.embedSWF(swf_file, "swf_placeholder", "304", "234", "9.0.98", false, flashvars, params, attributes);
}


function show_buy_links()
{
	if ($("#buy_links_list").is(":hidden")) {
		$("#buy_links_list").slideDown("slow");
	} else {
		$("#buy_links_list").slideUp("slow");
	}
	return false;
}


function current_events_id (elem, this_events_id) {
	// alert(this_events_id);
	$("#events_wrap p").removeClass('events_list_current');
	$("#events_wrap p").addClass('events_list');
	$(elem).removeClass('events_list');
	$(elem).addClass('events_list_current');
	
	$('#event_detail').html('<div style="text-align:center; margin: 0px auto; padding-top:80px; "><img height="32" width="32" border="0" src="./images/loading.gif"/><\/div>');
	
	$.ajax({
		url: './event_detail.php',
		type: 'GET',
		data: {events_id:this_events_id},
		dataType: 'json',
		timeout: 8000,
		success: success_events
	});
	
	return false;
	
}

function track_outbound(link) {
	var href = $(link).attr('href');
	
	$.ajax({
		url: './track_outbound.php',
		type: 'GET',
		data: {track_href:href},
		dataType: 'json',
		timeout: 8000
	});
	// alert(href);
	pageTracker._trackPageview('/outbound/' + href);
	return true;
}

