﻿ 
jQuery(document).ready(function($) {
    
    $('.header_menu ul li.megamenu a').click(function(e){
                    e.preventDefault();
                        $('#megamenu').stop('true', 'true').slideToggle('slow'); 
                        $('.header_menu ul li.megamenu').toggleClass( 'active' );
    });
    
        //Image Banner Rotator
        //Setting up the var's
        var onscreendelay     = 5000; // How long the image stays onscreen for.
        var fadein              = 1000; // How long the image takes to fade in.
        var clicked_delay     = 10000; // How long the system waits after a dot was clicked before it startes the timmer again.
        var scroll_loop        = 10000; //How long the timmer waits before its starts the next loop
        var i                   = 1; // Var for the current count in the system.
        
        // Add the UL structor to the page
        $('.mround-item-count .item-controller').append('<ul></ul><div class="divclear"></div>');
        
        //Fill the UL with an LI for each image present 
        var countz = 0;
        $('.mround .mround-item').each(function () {
                                                     if(countz == 0){
                                                         $('.mround-item-count .item-controller ul').append('<li class="active">&bull;</li>');
                                                         countz++;
                                                         }
                                                     else {
                                                           $('.mround-item-count .item-controller ul').append('<li>&bull;</li>');
                                                     }
                               })
        
        
        //The rotating function
        function scrollimg() {
            //alert('starting');
            $('.mround .mround-item:visible').stop(true, true).fadeOut('slow',function(){
                        $('.mround .mround-item').eq(i-1).stop(true, true).fadeIn(fadein);
                        $('.mround-item-count .item-controller ul li.active').removeClass('active');
                        $('.mround-item-count .item-controller ul li').eq(i-1).addClass('active');
                    });            
            if (++i > $('.mround .mround-item').size()) i = 1;
            
        };
        
        // The DOTS click function
        $('.mround-item-count .item-controller ul li').click(function(){
                                            
                                            //remove the active class from the li of the currently active 
                                            $('.mround-item-count .item-controller ul li.active').removeClass('active');
                                            $('.mround-item-count .item-controller ul li').eq($('.mround-item-count .item-controller ul li').index(this)).addClass('active');
                                            //set the var for what num was clicked
                                            var clicked = $('.mround-item-count .item-controller ul li').index(this);
                                            //Stop the scroller from running ny more loops
                                            clearInterval(scroll_img);
                                            
                                            //fade the current image away
                                            $('.mround .mround-item:visible').stop(true, true).fadeOut('fast', function(){
                                                
                                                //Set the var i to be the next image in the set
                                                i = clicked + 1;
                                                
                                                //fade in the clicked dot's corasponding image and start the timer after a set amount of time.
                                                $('.mround .mround-item').eq(clicked).fadeIn('slow').delay(3000,doscroll());
                                                function doscroll(){
                                                scroll_img = setInterval(scrollimg, scroll_loop)
                                                }                                                
                                                });
                                            
                                           });
        //start the rotator
        scroll_img = setInterval(scrollimg, scroll_loop);
});
 
function popupdiv(num){
 
    
    var val = 50;
    var x,y;
    try {
 
    if( window.innerHeight && window.scrollMaxY ) { // Firefox
    pageWidth = window.innerWidth + window.scrollMaxX;
    pageHeight = window.innerHeight + window.scrollMaxY;
    }
    else if( document.body.scrollHeight > document.body.offsetHeight ) { //    all but Explorer Mac
    pageWidth = document.body.scrollWidth;
    pageHeight = document.body.scrollHeight;
    }
    else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
    pageWidth = document.body.offsetWidth + document.body.offsetLeft;
    pageHeight = document.body.offsetHeight + document.body.offsetTop;
    }
    //alert("Page Height: " + pageHeight + "\nOffset: " + document.body.offsetHeight);
    
    //Set the position for the hover box
    //var yy = document.body.offsetHeight;
    
    var yy = document.body.offsetWidth / 2;
    var posx = yy - 390;
    document.getElementById('overlay' + num).style.height = pageHeight+"px";
    document.getElementById('overlay-content' + num).style.height = "450px";
    document.getElementById('overlay-content' + num).style.left = posx+"px";
    document.getElementById('overlay-content' + num).style.top = "100px";
    } catch(e) {}
    //alert(document.getElementById('wrapper').style.height);
    //alert(document.body.offsetHeight);
    document.getElementById('overlay' + num).style.display = "block";
    document.getElementById('overlay' + num).style.opacity = val/100;
    document.getElementById('overlay' + num).style.filter = 'alpha(opacity=' +val+ ')';
    document.getElementById('overlay' + num).style.MozOpacity = val/100;
    document.getElementById('overlay-content' + num).style.display = "block";
}
function closeoverlay(num){
        document.getElementById('overlay-content' + num).style.display = "none";
        document.getElementById('overlay' + num).style.display = "none";
        document.getElementById('overlay-content' + num).innerHTML = "";
}
 
 
function fixOrderedListElement( elem )
{
    var tmpContent = $(elem).html();
    $(elem).empty();
    $(elem).html('&nbsp;<span>' + tmpContent + '</span>');
}
$(document).ready(function() {
        
            $('body').removeClass('js-disabled'); // Allows for controlled styles if JS is disabled or broken.

            $('ol.blue li').each(function() { fixOrderedListElement( this ); });
            $('ol.black li').each(function() { fixOrderedListElement( this ); });
            $('ol.blue ol li').each(function() { fixOrderedListElement( this ); });
            $('ol.black ol li').each(function() { fixOrderedListElement( this ); });
            $('ol.blue').each(function() { $(this).removeClass('blue').addClass( 'blue-bullets' ); });
            $('ol.black').each(function() { $(this).removeClass('black').addClass( 'black-bullets' ); });
            
        });
