﻿$(document).ready(function () {
    $('#top-nav a, #footer a').each(function () {
        var cssClass = $(this).attr('href').substring($(this).attr('href').lastIndexOf('/') + 1);
        if (cssClass != '' && $('body').hasClass(cssClass))
            $(this).addClass('current');
    });

    jQuery.fn.center = function (width, height) {
        if (width == undefined) width = this.width();
        if (height == undefined) height = this.height();
        this.css("left", (($(window).width() - width) / 2) + $(window).scrollLeft() + "px");
        this.css("top", (($(window).height() - height) / 2) + $(window).scrollTop() + "px");
        return this;
    }
});

var preview = '<div class="preview">';
preview += '<div class="item-image"><div class="close"></div><img src="/img/loading.gif" alt="loading..." class="loading hide" /></div>';
preview += '</div>';
preview += '<div class="overlay"></div>';

function ImagePopUp(imageUrl, imageAltText) {
    var timeoutId = setInterval(function () { $('.preview .item-image .loading').removeClass('hide'); }, 250);
    $('body').append(preview);
    $('.preview').center();
    $('.overlay').css('height', $('body').height());
    var img = new Image();
    $(img).load(function () {
        clearInterval(timeoutId);
        $('.preview .item-image .loading').addClass('hide');
        $('.preview .item-image').append(img);
        $('.preview').center($(img).width(), $(img).height());
    }).attr('src', imageUrl).attr('id', imageAltText);
}

$('.preview .close, .overlay').live('click', function () {
    $('.preview').remove();
    $('.overlay').remove();
});

$(function () {
    $('input[type=text].sfsearchTxt')
        .attr('empty', 'Search')
        .val('Search')
        .focus(function () {
            if ($(this).val() == $(this).attr('empty'))
                $(this).val('');
        })
        .blur(function () {
            if ($(this).val() == '')
                $(this).val($(this).attr('empty'));
        });
});
