// Hot Shot Photo - JS Functions
// Most code is painstakingly handwritten by Justin Scheetz


// ---------------------------------- //
// Loading Graphics                   //
// ---------------------------------- //

$(document).ready(function(){
	ajaxTabLoading = $("#isLoading");
	ajaxTabWindow = $("#ajax-tab-window");
});

function changeURL(addon) {
  window.location.search += addon;
}

// Show Loading Graphic
function showLoading(){
	ajaxTabLoading.show();
}

// Hide Loading Graphic
function hideLoading(){
	ajaxTabWindow.show();
	ajaxTabLoading.hide();
	animationOn = false;
	ajaxtab_animationOn = false;
} // END Loading Graphics


// ---------------------------------- //
// Load a Tab Manually                //
// Used for item pagination/filtering //
// ---------------------------------- //

function ajaxTabLoad(ajaxTabFile,ajaxTabData){
	showLoading();
	ajaxTabWindow.hide();
	ajaxTabWindow.load("/tab_includes/"+ajaxTabFile+".php", ajaxTabData, hideLoading);
	currentAjaxTab = ajaxTabFile;
}


// ---------------------------------- //
// Profile Functions                  //
// ---------------------------------- //

// Refresh a single message
function loadSingleMessage(message_id,member_id){
	var messageData = "message_id="+message_id+"&member_id="+member_id;
	$('#message-post-'+message_id).load("/jquery_includes/single_message.php",messageData,function(){
		subWindowLoading.hide();
	});
}

// Refresh a single message
function loadSingleComment(comment_id,member_id){
	var commentData = "comment_id="+comment_id+"&member_id="+member_id;
	$('#message-post-'+comment_id).load("/jquery_includes/single_comment.php",commentData,function(){
		subWindowLoading.hide();
	});
}

var subWindowLoading = $("#isLoading");

// Refresh the Profile Messages
function refresh_profile_messages(className,profileData) {
	subWindowLoading.show();
	var classObject = $("."+className);
	classObject.hide();
	classObject.load("/jquery_includes/profile_messages.php",profileData,function(){
		classObject.fadeIn("fast");
		subWindowLoading.hide();
	});
}

// Refresh the Friend Activity
function refresh_friend_activity(className,profileData) {
	subWindowLoading.show();
	var classObject = $("."+className);
	classObject.hide();
	classObject.load("/jquery_includes/friend_activity.php",profileData,function(){
		subWindowLoading.hide();
		classObject.fadeIn("fast");
	});
}

// Refresh the Portfolio Tab
function refresh_portfolio_items(className,profileData) {
	subWindowLoading.show();
	var classObject = $("."+className);
	classObject.hide();
	classObject.load("/jquery_includes/portfolio.php",profileData,function(){
		subWindowLoading.hide();
		classObject.fadeIn("fast");
	});
}

// Refresh the Saved Tab
function refresh_saved_items(className,profileData) {
	subWindowLoading.show();
	var classObject = $("."+className);
	classObject.hide();
	classObject.load("/jquery_includes/saved.php",profileData,function(){
		subWindowLoading.hide();
		classObject.fadeIn("fast");
	});
} // END Profile Functions


// ---------------------------------- //
// LightBox Functions                 //
// ---------------------------------- //
function lightboxOff() {
	var closeWindowHotspots = $(".blackout,.close-window");
	var lightboxBlock = $('#lightboxBlock,#videoLightboxBlock');
	closeWindowHotspots.click(function(event){
		lightboxBlock.fadeOut('fast', function() {
			lightboxBlock.remove();
			closeWindowHotspots.fadeOut(function() { closeWindowHotspots.remove(); });
		});
	});
}

function lightboxForceOff() {
	var closeWindowHotspots = $(".blackout,.close-window");
	var lightboxBlock = $('#lightboxBlock,#videoLightboxBlock');
	lightboxBlock.hide();
	lightboxBlock.remove();
	closeWindowHotspots.hide();
	closeWindowHotspots.remove();
}
	
function getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
};

function getPageScroll() {
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}
	pageScroll = yScroll;
	return pageScroll;
};

function openLightbox(pagetoLoad,lightboxData) {
	
	$('body').append('<div class="blackout"></div><div id="lightboxBlock"><div class="lb-wrap"><span class="loading-graphic"></span></div></div>');

	var arrPageSizes = getPageSize();
	// Style overlay and show it
	$('.blackout').css({
		width: arrPageSizes[0],
		height:	arrPageSizes[1]
	}).show();
	// Get page scroll
	var arrPageScroll = getPageScroll();
	// Calculate top and left offset for the jquery-lightbox div object and show it
	$('#lightboxBlock').css({
		top: arrPageSizes[3] / 10
	});
	
	$("#lightboxBlock").load("/lightbox_includes/"+pagetoLoad+".php",lightboxData,function(){
		$('#lightboxBlock').fadeIn('fast',lightboxOff);
	});
} // END Lightbox Functions

function openVideoLightbox(pagetoLoad) {
	
	$('body').append('<div class="blackout"></div><div id="videoLightboxBlock"><div class="lb-wrap"><span class="loading-graphic"></span></div></div>');

	var arrPageSizes = getPageSize();
	// Style overlay and show it
	$('.blackout').css({
		width: arrPageSizes[0],
		height:	arrPageSizes[1]
	}).show();
	// Get page scroll
	var arrPageScroll = getPageScroll();
	// Calculate top and left offset for the jquery-lightbox div object and show it
	$('#videoLightboxBlock').css({
		top: arrPageSizes[3] / 10
	});
	
	$("#videoLightboxBlock").load("/lightbox_includes/"+pagetoLoad+".php","",function(){
		$('#videoLightboxBlock').fadeIn('fast',lightboxOff);
	});
} // END Lightbox Functions
