// JavaScript Document

var windowWidth = 0;
var windowHeight = 0;


$(document).ready(function(){
	windowWidth = $(window).width();
	windowHeight = $(window).height();
	
	$('.lightbox-overlay').css( {'width':windowWidth, 'height':windowHeight } );
	$('.release-detail-cont').css( {'margin-top': ( windowHeight/2 )-5 } );	
	
	$('#discog-det-close').live( 'click', function(e){
		e.preventDefault();
		$("#release-inner-cont").html( '');
		var newMargin = (windowHeight/2)+5;
		
		
		$("#release-detail-cont").animate({ height: '10', 'margin-top': ''+newMargin }, 200, '',function(){
			$('#discog-lightbox-overlay').css({'display':'none'});
		});
	});
	
	if( showVid ){
	
		videoWidth = windowWidth - 80;
		videoHeight = windowHeight - 80;
		
		$('.video-wrapper').css( {'width': videoWidth, 'height': videoHeight} );
		$('.vid-cont').css( {'width': videoWidth, 'height': videoHeight-20} );
		
		$('#video-lightbox-overlay').css( {'display': 'block'} );
		
		
		$('#skip-vid').live( 'click', function(e){
			e.preventDefault();
			
			$(".video-wrapper").animate({ height: '10' }, 200, '',function(){
				$('.vid-cont').html('');
				$('#video-lightbox-overlay').css( {'display': 'none'} );
			});
		});
	
	}
	else{
		$('#video-lightbox-overlay').html('');
	}
	
	
			
});


function get_current_gigs( pageNo ){
	var base = 'http://www.killingjoke.com/wp-content/themes/killingjoke/';
	$.ajax({
   		type: "GET",
   		url: base+"get_current_gigs.php?p="+pageNo,
   		cache: false,
		success: function(html){
    		$("#gigs-list").html(html);
  		}
 	});
	return false;
}

function get_past_gigs( pageNo ){
	var base = 'http://www.killingjoke.com/wp-content/themes/killingjoke/';
	$.ajax({
   		type: "GET",
   		url: base+"get_past_gigs.php?p="+pageNo,
   		cache: false,
		success: function(html){
    		$("#gigs-list").html(html);
  		}
 	});
	return false;
}

////////////////////////////////////////////
///****FUNCTIONS FOR TATTOOS PAGE*********//
////////////////////////////////////////////

function get_tat_form( fullBase ){
	var base = 'http://www.killingjoke.com/wp-content/themes/killingjoke/';
	
	$.ajax({
   		type: "GET",
   		url: base+"tats/get_tat_form.php?base="+fullBase,
   		cache: false,
		success: function( html){
    		$('#tats-lightbox-overlay').css( {'display': 'block'} );
			$('.tat-form-innercont').html( html );
			
			var formHeight = $("html").height() + 120;
			
			if( formHeight > windowHeight ){
				$('#tats-lightbox-overlay').css( { 'height': formHeight } );
				$('#tats-lightbox-overlay').css( { 'width': $(window).width() } );
			}
  		}
 	});
	
	return false;
}

function startUpload(){
	
	var inError = false;
	
	if( $('#user-image').val() == "" ){
		$('#user-image').addClass("tat-form-in-error");
		inError = true;
	}
	
	if( $('#user-name').val() == "" ){
		$('#user-name').addClass("tat-form-in-error");
		inError = true;
	}
	
	if( inError ){
		$('.tat-form-disclaimer').html("Please make sure that you have completed the required fields");
		return false;	
	}
	else{ 
		htmlText = '<div><img class="tat-loader" src="wp-content/themes/killingjoke/images/loader.gif" /></div>';
		htmlText += '<div class="tat-uploading-text" >Please wait while we upload your file...</div>';
		
		$('#submit-tat-but-cont').append( htmlText );	
		return true; 
	}
}


function clearUserTatForm(){
	htmlText = '<img class="tat-loader" src="http://www.killingjoke.com/wp-content/themes/killingjoke/images/loader.gif" />';
	htmlText += '<div class="tat-uploading-text" >Please wait while we upload your file...</div>';
	
	$('.tat-form-innercont').html( htmlText );	
}

function stopUpload( success, message ){
	$htmlText = '<div class="tat-uploading-text" >'+message+'</div>';
	$('.tat-form-innercont').html( $htmlText );	
		  
	return true;   
}

function closeTatsSubmit(){
	$(".tat-form-innercon").html( '');
	$('#tats-lightbox-overlay').css( {'display': 'none'} );
}


function get_tat_page( page ){
	var base = 'http://www.killingjoke.com/wp-content/themes/killingjoke/';
	
	$.ajax({
   		type: "GET",
   		url: base+"tats/get_next_tat_page.php?p="+page,
   		cache: false,
		success: function( html){
			$('.tats-carousel-cont').html( html );
  		}
 	});
	
	return false;
}

function swapTatPhoto( image ){
	
	
	htmlText = '<img class="tat-loader" src="http://www.killingjoke.com/wp-content/themes/killingjoke/images/loader.gif" />';
	$('.tats-gallery-image-cont' ).html( htmlText );
	$('.tats-gallery-image-cont' ).css( { 'height': $('.tats-gallery-image-cont img' ).height() } );
	
	$('.tats-gallery-image-cont' ).css( { 'height': $('.tats-gallery-image-cont' ).height() } );
	
	var img = $("<img />").attr('src', 'http://www.killingjoke.com/gallery/tattoos/'+image+'.jpg' ).load(function() {
      	$('.tats-gallery-image-cont' ).html(img);
		$('.tats-gallery-image-cont' ).css( { 'height': $('.tats-gallery-image-cont img' ).height() } );
	});
}


////////////////////////////////////////////
///****FUNCTIONS FOR DISCOG PAGE*********///
////////////////////////////////////////////


function get_info( release ){
	
	$('#discog-lightbox-overlay').css({'display':'block'});
	
	var attribs = release.canvas.attributes;
	var base = 'http://www.killingjoke.com/wp-content/themes/killingjoke/';
	
	$("#release-inner-cont").html('<div class="loader-cont" ><img src="wp-content/themes/killingjoke/images/loader.gif" /></div>');
	var innerContHeight = $("#release-inner-cont").height();
	var outerContHeight = innerContHeight + 20; //Outer cont height is equal to the inner cont plus the the 10px padding.
	var outerContMargin = ( windowHeight - outerContHeight ) / 2;
	
	$("#release-detail-cont").animate({ height: ''+innerContHeight, 'margin-top': ''+outerContMargin}, 400, '',function(){
		$("#release-inner-cont").css({'display':'block'});
	});

	
	var src = ''; var id = '';
	
	for(var i in attribs){
		var attrib = attribs[i];
		
		if( attrib.name == 'src' ){ src	= attrib.nodeValue; }
		if( attrib.name == 'id' ){ id	= attrib.nodeValue; }
	}
	
	$.ajax({
   		type: "GET",
   		url: base+"get_album_info.php?album="+id,
   		cache: false,
		success: function(html){
			
    		$("#release-inner-cont").html(html);
			innerContHeight = $("#release-inner-cont").height();
			outerContHeight = innerContHeight + 40; //Outer cont height is equal to the inner cont plus the the 10px padding.
			outerContMargin = ( windowHeight - outerContHeight ) / 2;
			
			
			//If the iner cont height is larger than the image height, calculate the margin required to center the image
			if( innerContHeight > 400 ){
				var imageMargin = ( innerContHeight -400 )/2;
				$('#release-inner-cont-img').css( {'margin-top': imageMargin } );	
			}
			
			
			$("#release-detail-cont").animate({ height: ''+outerContHeight, 'margin-top': ''+outerContMargin}, 400, '',function(){
			});
			
  		}
 	});
	return false;

	
}

function get_single_info( release ){
	
	$('#discog-lightbox-overlay').css({'display':'block'});
	
	var attribs = release.canvas.attributes;
	var base = 'http://www.killingjoke.com/wp-content/themes/killingjoke/';
	
	$("#release-inner-cont").html('<div class="loader-cont" ><img src="wp-content/themes/killingjoke/images/loader.gif" /></div>');
	var innerContHeight = $("#release-inner-cont").height();
	var outerContHeight = innerContHeight + 20; //Outer cont height is equal to the inner cont plus the the 10px padding.
	var outerContMargin = ( windowHeight - outerContHeight ) / 2;
	
	$("#release-detail-cont").animate({ height: ''+innerContHeight, 'margin-top': ''+outerContMargin}, 400, '',function(){
		$("#release-inner-cont").css({'display':'block'});
	});

	
	var src = ''; var id = '';
	
	for(var i in attribs){
		var attrib = attribs[i];
		
		if( attrib.name == 'src' ){ src	= attrib.nodeValue; }
		if( attrib.name == 'id' ){ id	= attrib.nodeValue; }
	}
	
	$.ajax({
   		type: "GET",
   		url: base+"get_single_info.php?album="+id,
   		cache: false,
		success: function(html){
			
    		$("#release-inner-cont").html(html);
			innerContHeight = $("#release-inner-cont").height();
			outerContHeight = innerContHeight + 40; //Outer cont height is equal to the inner cont plus the the 10px padding.
			outerContMargin = ( windowHeight - outerContHeight ) / 2;
			
			//If the iner cont height is larger than the image height, calculate the margin required to center the image
			if( innerContHeight > 400 ){
				var imageMargin = ( innerContHeight -400 )/2;
				$('#release-inner-cont-img').css( {'margin-top': imageMargin } );	
			}
			
			
			$("#release-detail-cont").animate({ height: ''+innerContHeight, 'margin-top': ''+outerContMargin}, 400, '',function(){
			});
			
  		}
 	});
	return false;

	
}
