/*!
 * Author: Ernest Lombardi
 *
 * Copyright (c) 2010 E.Lombardi: http://www.ernestlombardi.com/
 * Version: 1.0 (30-JAN-2010)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 */

$(function(){
		
	//if($(".selectedNav:contains('Gallery')").hasClass("selectedNav")){
	
		$("#carouselContainer").somethingWicked({
		
				//galleryPath: "http://www.ernestlombardi.com/images/gallery/ernest-lombardi-gallery.json?123",
				copyContainer: $("#carouselCopy p"),
				galleryContainerWidth: 928,
				galleryItemWidth: 90
				
		});
		
		$("#globalSearch").submit(function(){

			var tags = $("#search").attr("value").replace(", ", " ").replace(",", " ").replace("  ", " ").split(" ");
			
			$("#carouselContainer").somethingWicked({
					
				galleryPath: "http://api.flickr.com/services/feeds/photos_public.gne?tags="+ tags +"&tagmode=any&format=json&jsoncallback=?",
				copyContainer: $("#carouselCopy"),
				galleryContainerWidth: 874,
				galleryItemWidth: 175
					
			});	
			
			var feedNotice = "<strong>Please note:</strong> You are now viewing images hosted in the Flickr public feed tagged with the search terms you entered above: <strong>'" + tags + "'</strong>. Images in the public feed may not be work safe.";
			
			$("#copyContent").animate({backgroundColor: 'gold'}, 100).animate({ backgroundColor: 'white' }, 1000).find("p").html(feedNotice);

			
			return false;
		
		});
		
	//}
	/*else if($(".selectedNav:contains('Projects')").hasClass("selectedNav")){

		$("#scrollGallery").somethingWicked();
		
		$(".forecastContainer").meteorologica({
		
			zip: "04101"
		
		});		
	
	}*/

	$("#search").focus(function(){
	
		$(this).attr("value", "");
			
	});
	
	
	//drawBackground();
	
	
	$("nav a").hover(
		function(){
			if(!$(this).hasClass("selectedNav")){
				$(this).addClass("hoveredNav");	
			}
		}, function(){
			$(this).removeClass("hoveredNav");
	});
	
	$("header button").hover(
		function(){
			 $(this).addClass("hoveredButton");
		}, function(){
			 $(this).removeClass("hoveredButton");		
	});
	
	$(".sidebarWidget h2").click(function(){
			
				if(!$(this).parent().hasClass("sectionOpen")){
				
					$(".sectionOpen").removeClass("sectionOpen").find("ul").slideUp();
					
					$(this).parent().addClass("sectionOpen").find("ul").slideDown();
					
				}else{
				
					$(".sectionOpen").removeClass("sectionOpen").find("ul").slideUp();
					
				}
				
			});
	
});

function drawBackground() {
  //drawShadow();
  
  //delete ctx,  lingrad;

  var ctx = document.getElementById('backgroundCanvas').getContext('2d');
  
  ctx.globalAlpha = 1;
  
  ctx.fillStyle = 'black';  
  
  ctx.fillRect(0, 0, 900, 800);
  
  
  
  /*  
  ctx.fillStyle = 'lightYellow';  
  

  // Create linear gradients
  var lingrad = ctx.createLinearGradient(0, 0, 0, 135);
  
  var dateTime = new Date();
  
  switch(dateTime.getHours()){
  	case 07:
	case 08:
		lingrad.addColorStop(0, 'PaleTurquoise');  
		lingrad.addColorStop(0.5, 'LightSkyBlue');
		break;
	case 09:
	case 10:
	case 11:
	case 16:
		lingrad.addColorStop(0, 'DeepSkyBlue');  
		lingrad.addColorStop(0.5, 'LightSkyBlue');
		break;		
	case 05:
	case 06:
	case 17:
		lingrad.addColorStop(0, 'LightPink');  
		lingrad.addColorStop(0.5, 'LightSkyBlue');
		break;
	case 12:
	case 13:
	case 14:
	case 15:
		lingrad.addColorStop(0, 'RoyalBlue');  
		lingrad.addColorStop(0.5, 'LightSkyBlue');
		break;
	case 04:
	case 18:
	case 19:
	case 20:
	case 21:
	case 22:
	case 23:		
		lingrad.addColorStop(0, 'DarkSlateBlue');  
		lingrad.addColorStop(0.5, 'LightSkyBlue');
		break;	
	case 24:
	case 01:
	case 02:
	case 03:
		lingrad.addColorStop(0, 'MidnightBlue');  
		lingrad.addColorStop(0.5, 'LightSkyBlue');		
		break;		
	default:
		lingrad.addColorStop(0, 'DeepSkyBlue');  
		lingrad.addColorStop(0.5, 'LightSkyBlue');  
		break;
  }
  
	lingrad.addColorStop(0.65, 'lightYellow');
	lingrad.addColorStop(1, 'DarkGreen');   
	$("section #globalNav li a").css({"color":"whiteSmoke"});  

  // assign gradients to fill and stroke styles
  ctx.fillStyle = lingrad;
  
  // fill
  ctx.fillRect(0, 0, 900, 800);
  
  ctx.fillStyle = 'lightYellow';

  // set transparency value
  ctx.globalAlpha = 0.15;

  // Draw semi transparent circles
  for (i=0;i<7;i++){
      ctx.beginPath();
      ctx.arc(350, 90, 55+20*i, 0, Math.PI,true);
      ctx.fill();
  }
  
  ctx.save();
  
  //drawShadow();
  
  ctx.restore();
  */
  
  $("#backgroundCanvas").show(0);
  
}

function drawShadow(){
  var title = $("#siteName").text();
  var ctx = document.getElementById('backgroundCanvas').getContext('2d');

  ctx.shadowOffsetX = 0;
  ctx.shadowOffsetY = 0;
  ctx.shadowBlur = 4;
  ctx.shadowColor = "rgba(0, 0, 0, .85)";
  
  ctx.font = "bold 24px Times New Roman";
  
  ctx.fillStyle = "silver";
  ctx.fillText(title, 30, 34);	
}

