/* Custom jQuery Javascript */
/* Armchair Media 2010 */

/* homepage tray function */
function closetrays(){
	$(".open").animate({
	    	bottom: '-=240'
	  	}, 500, "easeOutCirc", function() {
	    $(this).removeClass("open");
	  	})
}

jQuery(function ($) {

    /* homepage tray click */
    $(".tray h2").click(function () {
        if ($(this).parent().hasClass("open")) {
            closetrays();
        } else {
            closetrays()
            $(this).parent(".tray").animate({
                bottom: '+=240'
            }, 500, "easeOutCirc", function () {
                $(this).addClass("open");
            })
        }
    });

    $("#home-video").click(function () {
        closetrays();
    })

    /* js workaround for Firefox's limited support for border radius on img elements */
    $('.gallery-large').each(function () {
        var thisbg = $(this).children("img").attr("src");
        var cssbg = "url(" + thisbg + ")";
        var cssObj = {
            'background-image': cssbg,
            'width': '940px',
            'height': '300px',
            "-moz-border-radius": "6px",
            "-webkit-border-radius": "6px",
            "border-radius": "6px"
        }
        $(this).css(cssObj);
        $(this).children("img").hide();
        //alert(thisbg);
    });

    $('#profile-carousel li a').each(function () {
        var thisbg = $(this).children("img").attr("src");
        var cssbg = "url(" + thisbg + ")";
        var cssObj = {
            'background-image': cssbg,
            'width': '300px',
            'height': '180px',
            "-moz-border-radius": "6px",
            "-webkit-border-radius": "6px",
            "border-radius": "6px",
            "display": "block"
        }
        $(this).css(cssObj);
        $(this).children("img").hide();
        //alert(thisbg);
    });

    /* generic rounder for images */

    $('.roundedimg').each(function () {
        var imgpath = $(this).attr("src");
        var imgwidth = $(this).attr("width");
        var imgheight = $(this).attr("height");
        var roundness = $(this).attr("rel");
        var cssroundness = roundness + "px";
        var cssbg = "url(" + imgpath + ")";
        var cssObj = {
            'background-image': cssbg,
            'width': imgwidth,
            'height': imgheight,
            "-moz-border-radius": cssroundness,
            "-webkit-border-radius": cssroundness,
            "border-radius": cssroundness,
            "display": "block"
        }
        $(this).replaceWith('<div class="cornerwrap"></div>');
        $('.cornerwrap').css(cssObj);
    });

    /* Hide the text inside text inputs stuff */
    swapValue = [];
    $(".swap-value").each(function (i) {
        swapValue[i] = $(this).val();
        $(this).focus(function () {
            if ($(this).val() == swapValue[i]) {
                $(this).val("");
            }
            $(this).addClass("focus");
        }).blur(function () {
            if ($.trim($(this).val()) == "") {
                $(this).val(swapValue[i]);
                $(this).removeClass("focus");
            }
        });
    });

    /* change hover color for homepage tray headers */
    $('#tray-news h2').hover(
	function () {
	    $(this).css({
	        'color': '#000',
	        'background-position': '-742px 0'
	    });
	},
	function () {
	    $(this).css({
	        'color': '#f00',
	        'background-position': '0 0'
	    });
	})

    $('#tray-forum h2').hover(
	function () {
	    $(this).css({
	        'color': '#000',
	        'background-position': '-742px -33px'
	    });
	},
	function () {
	    $(this).css({
	        'color': '#f00',
	        'background-position': '0 -33px'
	    });
	})

    $('#tray-social h2').hover(
	function () {
	    $(this).css({
	        'color': '#000',
	        'background-position': '-742px -66px'
	    });
	},
	function () {
	    $(this).css({
	        'color': '#f00',
	        'background-position': '0 -66px'
	    });
	})
});
