$(document).ready(function() {
       
    $(".lightbox").lightBox();

    /*$(".panel").hover(function() {
    $(this).find(".newbadge").hide();
    }, function() {
    $(this).find(".newbadge").show();    
    });*/

    Cufon.replace('.cufon', {
        hover: true
    });

    $("input[type=text], textarea").each(function() {
        if ($(this).val() == $(this).attr("title") && !$(this).hasClass("textBoxError")) {
            $(this).css("color", "#999999");
        }
    });

    $("input[type='text'], textarea").focus(function() {
        if ($(this).attr("title") == $(this).val()) {
            $(this).val('');
            $(this).removeAttr("style");
        }
    });

    $("input[type='text'], textarea").blur(function() {
        if ($(this).val() == "") {
            $(this).val($(this).attr("title"));
            if (!$(this).hasClass("textBoxError")) {
	            $(this).css("color", "#999999");
	        }
        }
    });

    $("#logo a").hover(function() {
        $("#logo span").show();
    },
    function() {
        $("#logo span").hide();
    });


    /* CAROUSEL */

    if ($('.carouselBannerArea').length != 0) {
        $('.carouselBannerArea').serialScroll({
            items: '.carouselItem',
            prev: '.carouselItem .previous a',
            next: '.carouselItem .next a',
            offset: 0,
            start: 0,
            duration: 800,
            force: false,
            stop: true,
            lock: true,
            cycle: false

        });
    };
    
    
    /* PANEL HEIGHTS */
    var maxHeight = 0;
    
    if ($("#threeColumns").length > 0) {
	    panelSelector = "#threecolumns .panel";
    } else {
	    panelSelector = ".panel";
    }
    
    $(panelSelector).each( function() {
	    var panelHeight = parseFloat($(this).height());
	    if (panelHeight > maxHeight) {
		    maxHeight = panelHeight;
	    }
    });
    
    $(panelSelector).css("height", maxHeight);

    
    /* SCROLLING PHOTOS */
    
    $("#scrollingphotosArea").css("overflow", "hidden");
    
    var paneHeight = $("#scrollingphotosArea").height();
    
    $("#paging a").click( function() {
	    var currentpage = parseFloat($("#paging .current").text().replace('[','').replace(']',''));
	    var clickedpage = parseFloat($(this).text().replace('[','').replace(']',''));
	    
	    //alert(currentpage + "|" + clickedpage); // debugging
	    
	    if (currentpage != clickedpage) {
		    var scrollHeight = paneHeight * (clickedpage - 1);
		    $("#paging a").each(function() {
			    $(this).removeClass("current");
			    $(this).html($(this).text().replace('[','').replace(']',''));			    
		    });		    
		    $(this).addClass("current");
		    $(this).text('[' + $(this).text() + ']');
		    //alert("scrolling to: " + scrollHeight); // debugging
		    
		    $("#scrollingphotosArea").scrollTo({top:'' + scrollHeight + 'px', left:'0px'}, 400);
		    
	    }
    });
});
