//Flickr Feed for Homepage
$.getJSON("http://api.flickr.com/services/feeds/photoset.gne?set=72157594386752579&nsid=55383947@N00&lang=en-us&format=json&jsoncallback=?", function(data){
  $.each(data.items, function(i,item){
    $("<img/>").attr("src", item.media.m).appendTo("#images")
      .wrap("<a href='" + item.link + "'></a>");
  });
});


//Set ready state
$(document).ready(function(){//Start Ready
						  
	//Testimonials
	$("#quotes div:random").fadeIn("slow"); 					   
    $(".jqAlbumParser").jqAlbumParser({
		showDesc: true,
        pluginExec : function(){
            $(this).jqGalViewII();
        }
    }).click();
	
	$("#thumbs a").click(function(event){
		$("#thumbs .on").removeClass();
		$(this).find("img").addClass("on");
		var showdiv_show = $(this).attr("href");
		$('.show').removeClass('show').hide();
		$(showdiv_show).fadeIn('slow').addClass('show');
		event.preventDefault();
	});
	
	$('#flashcontent div').hide();
	$("#thumbs a:first").click();
	
	
	
	
//Toggle Footer
$('.toggle a').click(function(event){
		event.preventDefault();
		var hideText = "Hide Menu";
		var showText = "Show Menu";
		if($(this).text() == hideText){
			$(this).text(showText);
			$(this).parents('div').animate({bottom: "-50px"}, 800).find('div').animate({bottom: "-50px"}, 800);
		}
		else{
			$(this).text(hideText);
			$(this).parents('div').animate({bottom: "0px"}, 800).find('div').animate({bottom: "0px"}, 800);
		}
		});

	
								
	
//Flickr Badge Reset Links to Go to Illustration page
$('#images a').attr('href', 'illustration.html');
$('#flickr_badge_wrapper a').attr('href','sketches.html');
$('#avatars #flickr_badge_wrapper a').click(function(event){
	event.preventDefault();
});





						   
$(".poplink").click(function(event){ //Triggers all pops from 'a' elements with class of 'poplink'
		var popdiv_show = $(this).attr("href");  
		$(popdiv_show).fadeIn('slow');
		event.preventDefault();
		$('#playerContainer').hide().parent().prepend('<img src="img/player.jpg" />')
		$('#youtube img').fadeIn('slow');
		popDiv();
	});
$(".findfriends a").click(function(event){ //Triggers ajax submit popup
		var popdiv_show = $(this).attr("href");  
		$(popdiv_show).fadeIn('slow');
		event.preventDefault();
		ajaxSignup();
		ajaxFriends();
		popDiv();
	});
$(".tooltip a").click(function(event){ //Triggers all tooltips from 'a' elements with class of 'tooltip'
		var popdiv_show = $(this).attr("href");  
		$(popdiv_show).toggle('slow');
		event.preventDefault();
	});
$(".pop .close").click(function(event){ //Triggers close of pop div from 'a' elements with class of 'close' and clicking on overlay background
   		closePopDiv();
		event.preventDefault();
		$('#youtube').find('img').remove()
		$('#playerContainer').show();
	});

$(".poptip .close").click(function(event){ //Triggers close of tooltips from 'a' elements with class of 'close'
   		closePopTip();
		event.preventDefault();
	});




//Clear Search Field
$(".comment").focus(function() {
		    if(this.value == "Type comment here!"){
				this.value = "";
				}
		});
$(".comment").blur(function() {
		    if(this.value == ""){
				this.value = "Type comment here!";
				}
		});


//Query (requires jquery.query.js)
	if($('body').hasClass('bodyhome')){
	var cat = $.query.get('cat');
	}
	if(cat == "thankyou"){
		$("#thankyou").fadeIn('slow');
		popDiv();
	}
	if(cat == "nogo"){
		$("#nogo").fadeIn('slow');
		popDiv();
	}
	
	
	// validate signup form on keyup and submit
	if(document.getElementById('bodyhome')){
		$("#contactform").validate({
		rules: {
			name: "required",
			email: {
				required: true,
				email: true
			},
			comment: "required"
		},
		messages: {
			name: "Please enter your name.",
			email: "Please enter a valid email address.",
			comment: "Please ask your question or leave a comment."
		}
	});
	}
		
//Detect Resizing of Window
var resizeTimer = null;
$(window).bind('resize', function() {
	if (resizeTimer) clearTimeout(resizeTimer);
	resizeTimer = setTimeout(resize, 100);
});

resize();

});//End Ready


//Sets offset for popup divs from top of browser window
function popDiv() {
		getHeight();
		if($.browser.msie){
		$(".pop").css("top", document.documentElement.scrollTop+50+'px');
		$('#content select').hide();
		}
		else {
		$(".pop").css("top", window.pageYOffset+100+'px');
		}
		$("#overlay").show();
}

function closePopDiv(){
	$(".pop").fadeOut('slow');
	$("#overlay").hide();
	if($.browser.msie) {
 		$('#content select').show();
		$("#footer").css("height", "200px");
 		}
	return false;
}


// Sets height for Overlay
function getHeight(){
	if (parseInt(navigator.appVersion)>3) {
 		if (navigator.appName=="Netscape") {
  		wind = window.innerWidth;
  		wind = window.innerHeight;
 		}
 		if($.browser.msie) {
  		wind = document.body.offsetWidth;
  		wind = document.body.offsetHeight;
 		}
	}
	var divh = document.getElementsByTagName('body')[0].offsetHeight;
	var lock = document.getElementById('overlay');
	if (divh >= wind){
	lock.style.height = divh +"px";
	}
	else {lock.style.height =wind +"px";}
}

// Detect Resolution <= 800px
function resize(){
	jQuery.browser.msie6 = jQuery.browser.msie &&
    parseInt(jQuery.browser.version) == 6 &&
    !window["XMLHttpRequest"];
	
	if (parseInt(navigator.appVersion)>3) {
 		if($.browser.msie) {
  		rwind = document.body.offsetWidth;
 		}
		else{
			rwind = window.innerWidth;
		}
	}
	if (rwind <= "800"){
			$('#footer .toggle a').fadeIn('slow');
			}
	else {
		if(!$.browser.msie6){
		$('#footer .toggle a').fadeOut('slow');
		}
		}
}

// Press Quotes Randomizer

jQuery.jQueryRandom = 0;
jQuery.extend(jQuery.expr[":"],
{
    random: function(a, i, m, r) {
        if (i == 0) {
            jQuery.jQueryRandom = Math.floor(Math.random() * r.length);
        };
        return i == jQuery.jQueryRandom;
    }
});



$(window).bind("load", function() {
	//homepage loading
	$('#blogfeedInner, #col1 div, #bodyhome #flickr_badge_uber_wrapper img, .delicious-posts, #blogfeedInner, #comicfeed').fadeIn('slow').parent().css('background-image', 'none');
	
	//Load Youtube
//	$.get("ajax-content/youtube.php", function(youtube){
	//$("#youtube").css('background-image', 'none').html(youtube);
//	});
	
	});

