/* ******************************************************************** */
/* janet.js															    */  
/*																		*/
/* Picard Art - Javascript routines				 						*/
/* 																		*/
/* Copywrite Max Perry, 2011											*/
/* All rights reserved.                                                 */
/* This code may not be redistributed in source or linkable object form */
/* without the consent of its author.                                   */
/*                                                                      */
/* Module Description: This file contains any global javascript 		*/
/* routines for picardart.com											*/
/*																		*/
/* ******************************************************************** */
$(document).ready(function() 
{	
	// -------------------------------------------------------------------
	// NAVIGATION
	// -------------------------------------------------------------------
	// Show navigation event
	$("#site_nav_bar ul li").hover(
		function() 
		{
			$(this).find('ul').show();
		}, 
		function()
		{
			$(this).find('ul').hide();
		}
	);
	
	// -------------------------------------------------------------------
	// PORTFOLIO: TBD move to own js file. Not used on every page...
	// -------------------------------------------------------------------
	$(".thumb_img").hover(
		function() 
		{
			// Don't do animation if on the current image thumb.
			if ($(this).hasClass("thumb_img_curr") == false)
			{
				$(this).fadeTo("fast", 1.0);
			}
		}, 
		function()
		{
			if ($(this).hasClass("thumb_img_curr") == false)
			{
				$(this).fadeTo("fast", 0.6);
			}
		}
	);
	
	$(".thumb_img").click(
		function()
		{
			var name = $(this).css('background-image');
			var patt = /\"|\'|\)/g;
			var cur_img = $(this).attr("id").match(/\d{1,2}/g).join();
			//alert(Shadowbox.cache[cur_img].link);
			//Shadowbox.open(Shadowbox.cache[cur_img]);
			// Sit pic box src to selected image.
			// TBD: Image path should NOT be hard coded!!!
			$("#pic_img").attr("src", "images/portfolio/" + name.split('/').pop().replace(patt,''));
			
			//$("#pic_img_link").attr("href", "images/portfolio/" + name.split('/').pop().replace(patt,''));
			$("#pic_img_link").attr("ref", cur_img);
			//$("#pic_link_box").html($("#img_link" + cur_img).html());
			// Copy description data to image description box. 
			$("#pic_desc_box").html($("#img_desc" + cur_img).html());
			
			// Set clicked thumb to current image and reset last one. 
			$(".thumb_img").removeClass("thumb_img_curr").fadeTo(0, 0.6);
			$(this).addClass("thumb_img_curr").fadeTo(0, 1.0);
		}
	);

	$("#pic_img_link").click
	(
		function ()
		{
			/*var i = 0;
			alert($("#pic_img_link").attr("ref"));
			alert(Shadowbox.cache[$("#pic_img_link").attr("ref")].link	);*/
			Shadowbox.open(Shadowbox.cache[$("#pic_img_link").attr("ref")]);
		}
	);
	
	// ------------------------------------------------------------------------------------------------
	// EDIT API - Move to own file!!!
	// ------------------------------------------------------------------------------------------------
	$("#num_pic_but").click
	(
		function ()
		{
			var theHTML = "";
			var num_pics = $("#num_pics").val();
			
			if (isNaN(num_pics) || num_pics <= 0) 
			{
				$("#num_pics_err").show();
				return;
			}
			
			$("#num_pics_err").hide();
			
			// Add loading image...
			$("#pic_input_box").html('<img src="../images/ajax-loader.gif" />&nbsp;&nbsp;&nbsp;Loading...');
			for (var i = 0; i < num_pics; i++) 
			{
				theHTML += "<input id='pic" + i + "' type='file' size='40'/><br/>";
			}
			
			$("#pic_input_box").html(theHTML+"<br/><br/><input type='submit' value='Submit' /><br/><br/>");
		}
	);
}); 
