$(document).ready(function() {
    
	/* CUFON */
    Cufon.replace('.cufon', {
        hover: true
    });

    
	/* INPUT DEFAULT TEXT */
    $("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");
	        }
        }
    });
    
    /* BOTTOM PANEL HEIGHTS */
    var bottomHeights = new Array;
    $("#bottomPanels .panel").each( function() {
	    bottomHeights.push($(this).height());
    });
    
   $("#bottomPanels .panel").height((Math.max(bottomHeights[0], bottomHeights[1])));
   
   /* MY CITY GATE MARQUEE */
   
   $(".marqueeContent").marquee("marqueeContent");
   
   /* HOMEPAGE CAROUSEL */
   $("#carousel").cycle({
        fx: 'scrollHorz',
        //speed: 800,
        //fx: "fade",
        speed: 800,
        timeout: 5000,
        next: '#carouselControls .next a',
        prev: '#carouselControls .prev a',
        before: onCarouselBefore
    });

    $("#carouselControls li").not(".next, .prev").find("a").click(function() {
        var page = parseFloat($(this).text()) - 1;
        $('#carousel').cycle(page);
        return false;
    });
    
    
   /* BUILDING PAGE CAROUSEL */
   $("#buildingCarousel").cycle({
        fx: 'scrollHorz',
        speed: 800,
        timeout: 5000,
        next: '#buildingCarouselControls .next a',
        prev: '#buildingCarouselControls .prev a',
        before: onBuildingCarouselBefore
    });
    
    $('#buildingCarousel').cycle("pause");

    $("#buildingCarouselControls li").not(".next, .prev").find("a").click(function() {
        var page = $("#buildingCarouselControls li a").index(this);
        $('#buildingCarousel').cycle(page);
        return false;
    });
    
    
});


function onCarouselBefore() {
    var page = $("#carousel img").index(this) + 1;
    $("#carouselControls li").not(".prev, .next").removeClass("current");
    $("#carouselControls li:eq(" + page + ")").addClass("current");
}


function onBuildingCarouselBefore() {
    var page = $("#buildingCarousel img").index(this);
    $("#buildingCarouselControls li").not(".prev, .next").removeClass("current");
    $("#buildingCarouselControls li:eq(" + page + ")").addClass("current");
}
