﻿$.extend($.fn.disableTextSelect = function() {
    return this.each(function(){
        if($.browser.mozilla){//Firefox
            $(this).css('MozUserSelect','none');
        }else if($.browser.msie){//IE
            $(this).bind('selectstart',function(){return false;});
        }else{//Opera, etc.
            $(this).mousedown(function(){return false;});
        }
    });
});

searchBoxinit = function() {
$('#searchForm').addClass("focus");
    $('#searchForm').removeClass("focus").addClass("idle");  
    $('#searchInput').focus(function() {
    $('#searchForm').removeClass("idle").addClass("focus");  
    });
    $('#searchInput').blur(function() {  
    $('#searchForm').removeClass("focus").addClass("idle");  
    });

};

startPageSliderInit = function(ax,px){    
    $('#searchForm').addClass("focus");
    $('#searchForm').removeClass("focus").addClass("idle");  
    $('#searchInput').focus(function() {
    $('#searchForm').removeClass("idle").addClass("focus");  
    });
    $('#searchInput').blur(function() {  
    $('#searchForm').removeClass("focus").addClass("idle");  
    });

    $('.contentBox').bind('mouseout', null, function(e) { $(this).children('a').css({'color' : '#8B8B8B'});$(this).children().children('span').css({'color' : '#4B4B4B'}); });
    $('.contentBox').bind('mouseover', null, function(e) { $(this).children('a').css({'color' : 'black'});$(this).children().children('span').css({'color' : 'black'}); });
        $("#globalBanner").easySlider({
        auto: ax || false,
        continuous: true,
        pause: px || 10000,
        speed: 300,
        controlsFade:        true,
        nextText: '<img src="images/design/global-banner-arrow-right.gif" alt="Next" />',
        prevText: '<img src="images/design/global-banner-arrow-left.gif" alt="Previous" />'
    });
    
    
    $("#globalBanner").parents('.roundedBoxContent').hover(function(){
        $("#prevBtn").fadeIn(300);
        $("#nextBtn").fadeIn(300);
    }, function(){
        $("#prevBtn").fadeOut(300);
        $("#nextBtn").fadeOut(300);
    });
    
    $("#prevBtn").hide().mouseover(function(e) { return false; });
    $("#nextBtn").hide();
    
    
    // local banner
    var $localBanner = $("#localBanner");
    var $localBanner_big = $('#localBanner-big');
    var $localBanner_slider = $('#localBanner-slider');
    var $localBanner_next = $('#localBanner-next');
    var $localBanner_prev = $('#localBanner-prev');
    var $localBanner_buttons = $localBanner_slider.find('.localBanner-button');
    var $localBanner_nav = $('#localBanner-nav');
    
    var localBanner_speed = 300;
    var localBanner_button_width = $localBanner_buttons.eq(0).width() + 1;
    var localBanner_button_height = 0;
    var localBanner_step = 2;
    
    $localBanner.disableTextSelect();
    $localBanner_buttons.each(function(n, item) {
        var height = $(item).height();
        if(height > localBanner_button_height) {
            localBanner_button_height = height;
        }
    });
    
    $localBanner_buttons.height(localBanner_button_height);
    $localBanner_nav.height(localBanner_button_height);
    $localBanner_slider.width(localBanner_button_width * $localBanner_buttons.size());
    
    $localBanner_next.click(function() {
        if(localBanner_step < $localBanner_buttons.size()) {
            ++localBanner_step;
        } else {
            localBanner_step = 2;
        }
        $localBanner_slider.stop(true, false).animate({ 'left': -((localBanner_step - 2) * localBanner_button_width)}, localBanner_speed);
    });
    
    $localBanner_prev.click(function() {
        if(localBanner_step > 2) {
            --localBanner_step;
        } else {
            localBanner_step = $localBanner_buttons.size();
        }
        $localBanner_slider.stop(true, false).animate({ 'left': -((localBanner_step - 2) * localBanner_button_width)}, localBanner_speed);
    });
    
    $localBanner_buttons.mouseover(function() {
        var $button = $(this);
        //if (!$button.hasClass('active')) {
        if(!$('[id=localBanner'+$button.attr('rel')+']', $localBanner_big).hasClass('active')) {
            $button.addClass('active').siblings().removeClass('active');
            $('.active', $localBanner_big).removeClass('active').stop(true, true).fadeOut(500);
            $('[id=localBanner'+$button.attr('rel')+']', $localBanner_big).stop(true, true).fadeIn(500).addClass('active');
        }
        return false;
    });
    
};

function renderFlash(swfPath, width, height, bgColor){
    document.write( "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http:\/\/fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\""+width+"\" height=\""+height+"\" id=\"feature\">" + 
    " <param name=\"allowScriptAccess\" value=\"sameDomain\" />" + 
    " <param name=\"movie\" value=\""+swfPath+"\" />" + 
    " <param name=\"quality\" value=\"high\" />" + 
    " <param name=\"bgcolor\" value=\""+bgColor+"\" />" + 
    " <embed src=\""+swfPath+"\" quality=\"high\" bgcolor=\""+bgColor+"\" width=\""+width+"\" height=\""+height+"\" name=\"feature\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http:\/\/www.macromedia.com/go/getflashplayer\" />" + 
    "</object>");
}
function renderMovie(src, width, height, autoplay, controller){
    if(src.indexOf(".mov")>-1) renderQT(src, width, height, autoplay, controller)
    else renderMP(src, width, height, autoplay, controller)
}
function renderQT(src, width, height, autoplay, controller){
    if(!width) width=320
    if(!height) height=240
    if(!controller) controller=false
    if(!autoplay) autoplay=true
    if(controller) height=height+16
 
    document.write( "<object classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" bgcolor=\"black\" width=\""+width+"\"height=\""+height+"\" codebase=\"http:\/\/www.apple.com/qtactivex/qtplugin.cab\">" + 
    " <param name=\"SRC\" value=\""+src+"\">" + 
    " <param name=\"AUTOPLAY\" value=\""+autoplay+"\">" + 
    " <param name=\"CONTROLLER\" value=\""+controller+"\">" + 
    " <param name=\"BGCOLOR\" value=\"white\">" + 
    " <embed src=\""+src+"\" width=\""+width+"\" height=\""+height+"\" autoplay=\""+autoplay+"\" controller=\""+controller+"\" pluginspage=\"http:\/\/www.apple.com/quicktime/download/\"></embed>" + 
    "</object>");
}
 
 
function renderMP(src, width, height, autoplay, controller){
    if(!width) width=320
    if(!height) height=240
    if(!autoplay) autoplay=1
    else autoplay=0
 
    if(controller){
        height=height+48;
        controller=1
    }else controller=0
 
    document.write( "<object id=\"MediaPlayer\" autoplay=\""+autoplay+"\" width=\""+width+"\" height=\""+height+"\" classid=\"CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95\" codebase=\"http:\/\/activex.microsoft.com\/activex\/controls\/mplayer\/en/nsmp2inf.cab#Version=5,1,52,701\" standby=\"Loading Microsoft Windows Media Player components...\" type=\"application\/x-oleobject\">" + 
    "    <param name=\"src\" value=\""+src+"\">" + 
    "    <param name=\"ShowControls\" value=\""+controller+"\">" + 
    "    <param name=\"ShowDisplay\" value=\"0\">" + 
    " <embed type=\"application/x-mplayer2\" " + 
    "     src=\""+src+"\"" + 
    "     name=\"MediaPlayer\"" + 
    "     width=\""+width+"\"" + 
    "     height=\""+height+"\"" + 
    "  autoplay="+autoplay+"" + 
    "  showcontrols=\""+controller+"\"" + 
    "  showdisplay=\"0\"" + 
    "  >" + 
    "  </embed>" + 
    "</object>");
}


// the fallowing code is added by Richard, starting at : 2005-03-03 ...
var zooma = new Object();

// Richard A. 2005-03-03
zooma.currentPageName = '';
zooma.changePage = function(id, inc) {
    var sel = document.getElementById(id);
    var currentindex=-1;
    for(currentindex=0;currentindex<sel.options.length;currentindex++) {
        if(sel.options[currentindex].value==zooma.currentPageName) {break;}
    }
    // check if this page is the last or first ...
    if((currentindex==-1) || (inc==1 && (currentindex==sel.options.length-1)) || (inc==-1 && (currentindex==0))) {return;}
    if(sel.options[currentindex+inc].value==null || (sel.options[currentindex+inc].value=='')) {return;}

    window.location.href = sel.options[currentindex+inc].value;
}

// Richard A. 2005-03-03
zooma.gotoSelectUrl = function(sel) {
    var url = sel.options[sel.options.selectedIndex].value;
    url = (url=='' || (url==null))?'':url;
    if(url!='') {
        window.location.href = sel.options[sel.options.selectedIndex].value;
    }
}

/*zooma.open_XmasWindow = function(url) {
    var strName = 'pfaffCalendar';
    window.open(url,strName,'width=538,height=555,scrollbars=no,resizable=no,left=100,top=100');
}*/

// Richard A. 2005-03-07
zooma.setMediaWindow = function() {
    /*
        resizes the window and layers, to make
        the media appear in the middle with some margin
    */
    var pageMarginWidth=60, pageMarginHeight=100;
    var contentMarginWidth=10, contentMarginHeight=10;
    var frm = document.getElementById("frmMediaProperties");
    var w = parseInt(frm.width.value);
    var h = parseInt(frm.height.value);
    window.resizeTo(w+pageMarginWidth, h+pageMarginHeight);
    var pageLayer = document.getElementById("pagemedia");
    pageLayer.style.width = w+contentMarginWidth+"px";
    window.focus();
}

// Richard A. 2005-03-07
zooma.openMediaWindow = function(url) {
    var strName = 'MediaWindow';
    window.open(url,strName,'width=800,height=500,scrollbars=no,resizable=no,left=100,top=100');
}
zooma.openExpWindow = function(url) {
    var strName = 'MediaWindow';
    window.open(url,strName,'width=840,height=500,scrollbars=no,resizable=no,left=100,top=100');
}
zooma.openSelectWindow = function(url) {
    var strName = 'MediaWindow';
    window.open(url,strName,'width=700,height=525,scrollbars=no,resizable=no,left=100,top=100');
}
zooma.open2170Window = function(url) {
    var strName = 'MediaWindow';
    window.open(url,strName,'width=872,height=553,scrollbars=no,resizable=no,left=100,top=100');
}
function openXmasWindow(str) {
    var strName = 'MediaWindow';
    window.open(url,strName,'width=620,height=620,scrollbars=no,resizable=no,left=100,top=100');
}

// Programmed 2002-08-20 by Richard Appelgren (c) 
// usage : 
// var theValue = request.querystring("test2")); 
var request = new Object();
request.querystring = function(skey) { 
    var val="", qs, arr = [], nr, key = skey+"="; 
    if(window.location.href.indexOf("?")>-1) { 
        qs = window.location.href.substring(window.location.href.indexOf("?")+1); 
        arr = qs.split("&"); 
        for(var i=0;i<arr.length;i++) { 
            nr = arr[i].lastIndexOf(key); 
            if(nr>-1) { 
                val = arr[i].substring(nr+key.length); 
                break; 
            } 
        } 
    } 
    return val; 
}

$.fn.reorder = function() {
 
  // random array sort from
  // http://javascript.about.com/library/blsort2.htm
  function randOrd() { return(Math.round(Math.random())-0.5); }
 
  return($(this).each(function() {
    var $this = $(this);
    var $children = $this.children();
    var childCount = $children.length;
 
    if (childCount > 1) {
      $children.remove();
 
      var indices = new Array();
      for (i=0;i<childCount;i++) { indices[indices.length] = i; }
      indices = indices.sort(randOrd);
      $.each(indices,function(j,k) { $this.append($children.eq(k)); });
 
    }
  }));
}
