if (typeof console === 'undefined') {console = {log:function(){}};};


(function ($) {



var blockshadow = $('<div class="shadow-bottom"><div></div></div>');
function add_blockshadow() {
	var me = $(this);
	// wrap shadow-container around our shadowed div
	var cont = me.wrap('<div class="shadow-container clearfix"></div>').parent();
	if (matches = ('' + me[0].className).match(/grid_[0-9]{1,2}/)) {
	    cont.addClass(matches[0]);
	    me.removeClass(matches[0]);
	}
    var shadow = blockshadow.clone();
	shadow.css({
	    'margin-right': me.css('margin-right'),
	    'margin-left': me.css('margin-left'),
	    'margin-bottom': me.css('margin-bottom')
	});
	me.css({'margin-bottom': 0});
	cont.append(shadow);
	
};


function background() {
    // background
    var bgimgpath = $('body').css('backgroundImage').replace(/url\("?|"?\)/g, ''),
        bgimg = $('<img>').attr('alt', 'Background image').attr('src', bgimgpath),
        bgwrap = $('<div>').html(bgimg).append($('<div>')).attr('id', 'bgwrap');
    

    function resize() {
        var BGHEIGHT = 1600,
            BGWIDTH = 1000, // image dimensions
            wrapperWidth = Math.max(1000, $('#wrapper').width());
        bgwrap.css({
            height: $('#wrapper').height() + 'px',
            width: wrapperWidth + 'px'
        });
        
        var imgWidth = Math.max(BGWIDTH, $('#wrapper').width(), $('#wrapper').height() * BGWIDTH / BGHEIGHT),
            imgHeight = Math.max(BGHEIGHT, $('#wrapper').height(), $('#wrapper').width() * BGHEIGHT / BGWIDTH);
        
        bgimg.css({
            width: imgWidth + 'px',
            height: imgHeight + 'px',
            left: Math.max(0, wrapperWidth - imgWidth) + 'px'
        });
    };
    
    
    $('#wrapper').before(bgwrap);
    $('body').css({backgroundImage: 'url()'});
    resize();
    $(window).load(resize).resize(resize);
    
};



$(function () {
	Cufon.replace('#breadcrumbs', {fontFamily: 'SohoStd Medium'});
	Cufon.replace('h1,h2,h3,h4,h5,h6,blockquote, .twitterlink, .twitter .tweet', {fontFamily: 'SohoStd Regular'});
	
	$('ol.zebra li:even,ul.zebra li:even,tbody tr:even').addClass('even');
	
    
    if (!$.browser.msie || $.browser.msie && parseInt($.browser.version) > 6) {
        $('.blockshadow').each(add_blockshadow);
    }
    
    background();

    $('.height-equal').each(function () {
        if (!this.equalHeight_check) {
            var me = $(this),
                height = me.height();
            me.siblings('.height-equal').each(function() {
                this.equalHeight_check = true;
                height = Math.max(height, $(this).height());
            });
            me.css({height: height + 'px'});
            me.siblings('.height-equal').css({height: height + 'px'});
        }
    });
    
    
    // give required field labels a class for styling
    $('input.required, select.required, textarea.required').parent('li, tr').find('label, th').addClass('required');

    // add prompts to form elements
    $('form.titleprompt input, form input.titleprompt').formPrompt();
    
        
    // facilitate zebra striping in uls and tables, checkbox-specific styles
    $('ul li:even, table tr:even').addClass('alt');
    $('input[type=checkbox]').addClass('checkbox');
 
    
    // ie6 users can stick it when it comes to customised select boxes
    if (!$.browser.msie || $.browser.msie && parseInt($.browser.version) > 6) {
        $('select').SelectCustomizer();
    }
    
    
    //$('input.datepicker').datepicker({dateFormat: 'yy-mm-dd'});

    // Kill links to self
    $('a').each(function(i, item) {
        if (item.href == ('' + window.location).replace(/#.*$/, '')) {
            $(item).addClass('current');
        }
    });
    
    function getbase(url) {
        return ('' + url).replace(/https?\:\/\/[^\/]*/, '').replace(/^\/|\/$/g, '').split('/')[0]
    };

    // Nav links are given "current" class for their entire subsection
    $('#nav a').each(function(i, item) {
        if (getbase($(item).attr('href')) == getbase(window.location)) {
            $(item).addClass('current');
        }
    });


    if (true || !$.browser.msie || $.browser.msie && parseInt($.browser.version) > 6) {
        $('#nav a').hover(
            function() {
                $(this).addClass('hovered');
            },
            function() {
                $(this).removeClass('hovered');
            }
        );
    };
    
    
    
    
});






})(jQuery);
