//toggle var
var d = false;

$(document).ready(function() {	

	//png fix
	$("#header_container").pngFix();
	$("#susan").pngFix();	
	
	//$("#tabs").css("display","block");
	
	// ajax link handling
	 $('.ajaxlink').livequery('click', function(event) { 
	 
		tempTarget = $(this).attr('href');
		thisTarget = tempTarget;	

		$("#content").fadeTo(750, .1, function() {
			$(this).load(thisTarget);
		}).fadeTo(750, 1);	
		
		return false;
	});	
	 
	//subtitute for innerHtml
	function replaceHtml(el, html) {
		var oldEl = typeof el === "string" ? document.getElementById(el) : el;
		var newEl = oldEl.cloneNode(false);
		newEl.innerHTML = html;
		oldEl.parentNode.replaceChild(newEl, oldEl);
		return newEl;
	};		 

//	$("#firstimage").load(function () {
			//set homepage slideshow
		$('ul#home').cycle({
		   fx: 'fade',
		   timeout:5000,
		   continuous: true,
		   speedIn: 5000,
		   speedOut: 5000,
		   delay: 4000
		});					
//	});	
	
	 // sub content catgeory link handling	
	 $('.category-link').livequery('click', function(event) { 
	 
		tempTarget = $(this).attr('href');
		thisTarget = tempTarget;	

		$("#content").fadeTo(750, .1, function() {
			$(this).load(thisTarget);		
		}).fadeTo(750, 1);
		
		return false;
	});		

	//toggle color function
	function toggleColor() {
			 
				 if(d == true) {
					 $("#fade").colorBlend([{fromColor:"white", toColor:"black", isFade:false, cycles:1, duration: 150}]);
					 d = false;
				} else if(d == false) {
					$("#fade").colorBlend([{fromColor:"black", toColor:"white", isFade:false, cycles:1, duration: 150}]);
					d = true;
				}
		}
		
	//fade to black
	$('.to-black').livequery('click', function(event) { 
		 if(d == true) {
			 $("#fade").colorBlend([{fromColor:"white", toColor:"black", isFade:false, cycles:1, duration: 150}]);
			 d = false;
		}
	});
	
	//fade to white
	$('.to-white').livequery('click', function(event) { 
		 if(d == false) {
			$("#fade").colorBlend([{fromColor:"black", toColor:"white", isFade:false, cycles:1, duration: 150}]);
			d = true;
		}
	});			
										
	
	//thumbnail click handling
	 $("#thumbnail li img").livequery('click', function(event) { 
		
		var url = $(this).attr("src");	
		var title = $(this).attr("alt");
		var largeimg = url + ".large.jpg";
		var fullTitle = $(this).attr("alt") + '<br /><br />For full view, click image.';

		replaceHtml("copyright", fullTitle);
		$("#large img").hide().attr("src", largeimg);
		$("#large img").attr("alt", title);
		
		//set magnify class
		//$("#large img").addClass('magnify');
		
		 if(d == true) {
			$("#large").css("background", "url(images/loader.gif) no-repeat 50% 50%");
		 } else {
			 $("#large").css("background", "url(images/loader-black.gif) no-repeat 50% 50%");
		 }
		
		return false;
	});		


	//hide large img until loaded then fadeIn
	$("#large>img").livequery('load', function(event) {
		$("#large>img:hidden").fadeIn("slow");
		 $("#large>img").lightBox();
		
	});
	
	// lets use the shortcut
	$(function() {
		var addClickHandlers = function() {
			$("a.clickMeToLoadContent").click(function() {
				$("#target").load(this.href, addClickHandlers);
			});
		};
		addClickHandlers();
	});	
		
	init("#image");
	}
	); 
  
  function init(target){
    $('a.slide').each(
      function() {
        if(this.getAttribute('href') &&
          (this.getAttribute('rel') == 'pagination')) {
          this.onclick = function(){
            
				varhref = this.href;
				vartitle = this.getAttribute("title");			
				
				$("#image_inner").fadeOut(500).fadeTo(750, 1, function() {
						$("#image").html('<a href="' + varhref + '"><img src="' + varhref + '" alt="' + vartitle + '" title="' + vartitle + '" /></a>')
				}).fadeIn(500);				
							   
				$("#image_text").html(this.getAttribute("title"));		   						   
						   
            return false;
          }
        }
      }
    );
  }
// ]]>
