﻿/// <reference path="jquery-1.3.2.min.js" /> 
/* 
Global javascript file.
(C) 2009 Kian Ryan, Orange Tentacle
*/

var $j = jQuery.noConflict();
$j.ajaxSetup({ cache: false });

$j(document).ready(function() {
    var ref = new GlobalPageObject();
    ref.init();
});

$j.browser.versionOver6 = function() {  
    var re = /MSIE (\d+)/ig;  
    var match;  
    while (match = re.exec(window.navigator.userAgent)) {  
        if (match[1] > 6) {  
            return true;  
        }  
    }  
    return false;  
} 
  
$j.browser.msie6 =  
    $j.browser.msie &&
    ! $j.browser.versionOver6(); 

function GlobalPageObject() { }

GlobalPageObject.prototype = {

    newsRotate: 0,

    init: function() {
        var ref = this;
        ref.bindNews(ref);
        ref.suckerfish(ref);

        DDFix();
    },

    bindNews: function(ref) {
        $j('ul.rotatenews li').hide();
        $j('ul.rotatenews').each(function() { $j('li:first', this).show(); });
        ref.newsRotate = window.setTimeout(function() { ref.rotateNews(ref); }, 6000);
        $j('ul.rotatenews').hover(
            function() {
                window.clearTimeout(ref.newsRotate);
            },
            function() {
                ref.newsRotate = window.setTimeout(function() { ref.rotateNews(ref); }, 6000);
            });
    },

    rotateNews: function(ref) {
        $j('ul.rotatenews').each(function() {
            var thisItem = $j('li:visible', this);
            var nextItem;
            if ($j('li:last:visible', this).length == 1) {
                nextItem = $j('li:first', this);
            } else {
                nextItem = $j('li:visible', this).next();
            }

            thisItem.fadeOut('slow', function() {
                if ($j.browser.msie) {
                    this.style.removeAttribute('filter');
                }
                // nextItem.style.removeAttribute('filter');
                nextItem.fadeIn('slow', function() {
                    if ($j.browser.msie) {
                        this.style.removeAttribute('filter');
                    }
                });
            });
        });

        ref.newsRotate = setTimeout(function() { ref.rotateNews(ref); }, 6000);
    },

    /* Implements the suckerfish and Curfon replacement functionality. */
    suckerfish: function(ref) {

        // Top level elements.
        $j('ul.menu li.top').each(function() {
            $j(this).hover(
                function() {
                    $j('ul.menu li').removeClass('shover');
                    $j(this).addClass('shover');
                    if ($j(this).hasClass('short')) {
                        $j(this).addClass('short-hover');
                        Cufon.replace('a.standard');
                        if ($j.browser.msie6) {
                            DD_belatedPNG.fix('a.standard');
                        }
                    } else if ($j(this).hasClass('long')) {
                        $j(this).addClass('long-hover');
                        Cufon.replace('a.standard');
                        if ($j.browser.msie6) {
                            DD_belatedPNG.fix('a.standard');
                        }
                    }
                },
                function() {
                    $j(this).removeClass('shover');
                    if ($j(this).hasClass('short')) {
                        $j(this).removeClass('short-hover');
                        Cufon.replace('a.standard');
                        if ($j.browser.msie6) {
                            DD_belatedPNG.fix('a.standard');
                        }
                    } else if ($j(this).hasClass('long')) {
                        $j(this).removeClass('long-hover');
                        Cufon.replace('a.standard');
                        if ($j.browser.msie6) {
                            DD_belatedPNG.fix('a.standard');
                        }
                    }
                }
            );
        });

        $j('ul.menu li').each(function() {
            $j(this).hover(
                function() {
                    $j(this).addClass('shover');
                },
                function() {
                    $j(this).removeClass('shover');
                }
            );
        });

        $j(document).click(function() {
            $j('ul.menu li').removeClass('shover')
        });

    }

}

function DDFix() {
    if ($j.browser.msie6) {
        DD_belatedPNG.fix('.button-blue, ul.short-tabs li, .button-blue-large, .button-orange-large, .button-orange-very-large, .button-preset, .button-tall-orange, .button-tall.config, .prev, .next ,a.standard, img');
    }
}



    



