if ( typeof window.$ != 'function' ) {
    window.$ = function () {
      var elements = new Array();
      for (var i = 0; i < arguments.length; i++) {
        var element = arguments[i];
        if (typeof element == 'string')
          element = document.getElementById(element);

        if (arguments.length == 1)
          return element;

        elements.push(element);
      }

      return elements;
    }
}



function webSearch(){
    var link = "/search?q=";    
    var elm = $("#seekword");
    if (elm.val() != "") {
        document.location.href = link + encodeURIComponent(elm.val());
        return false;
    }
    else
    {
        var elmQ = $("q");
        if(elmQ){
            document.location.href = link + escape(elmQ.val());
            return false;
        }
    }
    
    
}

function popup(file,header,width,height){
     var _popup = document.open(file,header,'left='+Math.round(screen.availWidth/2-width/2)+',top='+Math.round(screen.availHeight/2-height/2)+',width='+width+',height='+height+',resizable=no,location=no,directories=no,menubar=no,scrollbars=no,status=no');
     _popup.window.focus();
}

function showhideContainer(elementID)
{
    var e = $(elementID);
    
    if(!e) return;
    
    e.style.display = e.style.display == "" ? "none" : "";
}

$(document).ready(function() {
    $('.head', this).css("cursor", "pointer");
    $('.head', this).siblings().hide();
    $('.expanded', this).siblings().show('fast');
    $('.expanded', this).addClass('selected');
    $('.expanded', this).parent().attr({ id: 'expanded' });

    var expandedid = 'expanded';
    $('.head', this).bind('click', function() {
        $('#' + expandedid + ' .head').siblings().hide('fast');
        $('#' + expandedid + ' .head').siblings().removeClass('selected-item');
        $('#' + expandedid + ' .head').removeClass('selected');
        var currentid = $(this).parent().attr('id');
        $('#' + expandedid).attr({ id: '' });
        if (currentid !== expandedid) {
            $(this).siblings().addClass('selected-item');
            $(this).siblings().show('fast');
            $(this).addClass('selected');
            $(this).parent().attr({ id: expandedid });
        }
        return false;
    })
}

)

$(document).ready(
    function() {
        $('.expanded-list', this).css("cursor", "pointer");
        $('.expanded-list', this).children('ul').hide();

        $('.expanded-list', this).bind('click', function() {
            var visible = $(this).children('ul').is(':visible');
            $(this).children('ul').show('fast');
            return visible;
        })
    }
)

$(function() {
    var tabContainers = $('#document div.tabs > div');
    tabContainers.hide().filter(':first').show();

    $('div.tabs ul.tabNavigation a').click(function() {
        tabContainers.hide();
        tabContainers.filter(this.hash).show();
        $('div.tabs ul.tabNavigation a').removeClass('selected');
        $(this).addClass('selected');
        return false;
    }).filter(':first').click();
});

$(document).ready(function() {

    //select all the a tag with name equal to modal
    $('a[name=modal]').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();

        //Get the A tag
        var id = $(this).attr('type');
        if (id == "") id = "#dialog";

        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Set heigth and width to mask to fill up the whole screen
        $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

        //transition effect
        $('#mask').fadeIn(500);
        $('#mask').fadeTo("fast", 0.5);

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();

        //Set the popup window to center
        $(id).css('top', winH / 2 - $(id).height() / 2);
        $(id).css('left', winW / 2 - $(id).width() / 2);
       
        //transition effect
        $(id).fadeIn(100);

    });

    //if close button is clicked
    $('.window .close').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();

        $('#mask').hide();
        $('.window').hide();
    });

    //if mask is clicked
    $('#mask').click(function() {
        $(this).hide();
        $('.window').hide();
    });

});