//*************************************************************************************
// File     : squirrel_functions.js
// Version  : 1.0
// Requires : jquery.js (version 1.2.6+), braingnat.js (version 0.0.7+)
// Author   : Kyle Weems (ksw), modifications to scrollLandscape and navKnob by William Flake (http://www.williamflake.com/)
// Origin   : www.cssquirrel.com
// Created  : October 09, 2008
// Modified : December 06, 2009
//*************************************************************************************

var scrollL = 0;

$(document).ready(function() { activationSequence(); });

function activationSequence() {
    checkBrowser();
    /*setContentHeight(80);
    $(window).resize(function() { setContentHeight(80); });*/
    makeFlickrBadgeOpenNewWindow();
    showCurrentFlickrBadgeTitle();
    navKnob();
    scrollLandscape();
    search();
    setCaptchaEvent();
}

function checkBrowser() {
    if ($('#cloudLayer').css('font-size') != "1px") {
        scrollL = 1;
    }
}

function makeFlickrBadgeOpenNewWindow() {
    $('.flickr_badge_image a').attr('target', '_blank');
    $('.flickr_badge_image a').attr('title', 'Image from my Flickr feed');
}

function showCurrentFlickrBadgeTitle() {
    $('#flickr_badge_wrapper img').bind('mouseover', function(event) {
        $('#flickr_badge_wrapper img.current').removeClass('current');
        $(this).addClass('current');
        $('#currentPhotoTitle').html($(this).attr('title'));
    });
}

function scrollLandscape() {
    if (scrollL == 1) {
    	cloud = 0; 
    	mountain = 0;
    	hill = 0;
    	forest = 0;
    	$("#branding").bind('mouseenter',function(e) {
			cloud = parseInt($("#cloudLayer").css("background-position"))*4-e.clientX;
            mountain = parseInt($("#mountainLayer").css("background-position"))*3-e.clientX;
            hill = parseInt($("#hillLayer").css("background-position"))*2-e.clientX;
            forest = parseInt($("#forestLayer").css("background-position"))-e.clientX;
        });
        $("#branding").mousemove(function(e) {
            mouseX = e.clientX;
            $("#cloudLayer").css("background-position", Math.floor((mouseX+cloud)/ 4)%800 + "px 0");
            $("#mountainLayer").css("background-position", Math.floor((mouseX+mountain)/ 3%652) + "px 0");
            $("#hillLayer").css("background-position", Math.floor((mouseX+hill)/2%800) + "px 0");
            $("#forestLayer").css("background-position", (mouseX+forest)%800 + "px 0");
        });
    }
}

function navKnob() {
    $('#liNavKnob').bind('click', function(e) {
        if ($('#liNavKnob').hasClass('expanded')) {
            $('#liNavKnob').removeClass('expanded');
            $('#ulNav').animate({ left: -400 }, 1000);
        } else {
            $('#liNavKnob').addClass('expanded');
            $('#ulNav').animate({ left: -83 }, 1000);
        }
    });
}



function search() {
    $('#search form').submit(function() {
        window.location = "/?s=" + $('#search input').attr('value');
        return false;
    });
    $('#search button').bind('click', function() {
        window.location = "/?s=" + $('#search input').attr('value');
        return false;
    });
}

// setCaptchaEvent()
function setCaptchaEvent() {
    if ($('.imgCap').length > 0) {
        $('.imgCap').bind("click", function() { $('.imgCap').removeClass('selected'); $(this).addClass('selected'); $('#captchaAnswer').attr('value', this.id); });
        $('#capRow a').bind("click", function() {
            $(this).children('img').click();
            return false;
        });
    }
} // end of function setCaptchaEvent()