/* jQuery flash-replacement menu. Cool animations, blah blah
** Designed using arrays, but could easily be replaced with
** AJAX scripts to get the menu items dynamically form a database
*/
var mainItemCount = 7;
var subItemCount = [];
var mainItems = [];
mainItems[0] = "About Us";
mainItems[1] = "Our Services";
mainItems[2] = "Request Quote";
mainItems[3] = "Our Portfolio";
mainItems[4] = "DANIMA Talk";
mainItems[5] = "Contact Us";
//Home has no sub items
mainItems[6] = "Home";
var subItems = [];
subItems[0] = new Array();
subItems[1] = new Array();
subItems[2] = new Array();
subItems[3] = new Array();
subItems[4] = new Array();
subItems[5] = new Array();
subItems[6] = new Array();
subItems[7] = new Array();
subItems[8] = new Array();
subItems[9] = new Array();
subItems[10] = new Array();
subItems[11] = new Array();
subItems[12] = new Array();
subItems[13] = new Array();
subItems[14] = new Array();
subItems[15] = new Array();
//About Us
subItems[0][0] = new Array("Our History", "/aboutus/history");
subItems[0][1] = new Array("Meet The Team", "/aboutus/meettheteam");
subItems[0][2] = new Array("Our Partners & Affiliates", "/aboutus/partnerships");
subItems[0][3] = new Array("Our Philosophy", "/aboutus/philosophy");
subItems[0][4] = new Array("Employment Opportunities", "/aboutus/empopportunities");
subItems[0][5] = new Array("Contact Us", "/contactus/");
subItemCount[0] = 6;
//Our Services
subItems[1][0] = new Array("Design", "/webdesign/");
subItems[1][1] = new Array("Hosting", "/webhosting/");
subItems[1][2] = new Array("Domain Registration", "/domains/");
subItems[1][3] = new Array("Systems & Solutions" ,"/systems_solutions/");
subItems[1][4] = new Array("E-Commerce","/ecommerce/");
subItems[1][5] = new Array("Print","/print_graphic/");
subItems[1][6] = new Array("SEO","/seo/");
subItemCount[1] = 7;
//Danima News
//subItems[2][0] = new Array("Current Issue","/danimanews/");
//subItems[2][1] = new Array("Subscribe","/danimanews/subscribe");
//subItems[2][2] = new Array("Archives","/danimanews/archives");
subItemCount[2] = 3;
//Our Portfolio
subItems[3][0] = new Array("Best of the Web","/ourportfolio/");
subItems[3][1] = new Array("Web Systems","/ourportfolio/systems/");
subItems[3][2] = new Array("Print and Graphic","/print_graphic/portfolio/");
subItems[3][3] = new Array("Client List","/ourportfolio/clients/");
subItemCount[3] = 4;
//Danima talk
subItems[4][0] = new Array("Facebook","http://www.facebook.com/group.php?gid=3314525709");
subItems[4][1] = new Array("Twitter","http://twitter.com/danima09");
subItems[4][2] = new Array("Blog","/blog/");
subItems[4][3] = new Array("Archives","/blog/archives");
subItemCount[4] = 4;
//Contact Us
subItems[5][0] = new Array("Contact Form", "/contactus/");
subItems[5][1] = new Array("Map & Directions", "/contactus/map");
subItemCount[5] = 2;
//*************************
// THE FOLLOWING ARE THE LEFT SIDEBAR SPECIFIC SUBMENUS
// THEY DONT MATCH A mainItem.
// To call these, the subPage must set a variable called
// currentSub == ID# before the menu.js is included
//Website Hosting
subItems[14][0] = new Array("Overview", "/webhosting/");
subItems[14][1] = new Array("Hosting Packages", "windw:http://www.danimahosting.com/hosting/");
subItems[14][2] = new Array("Hosting Support", "windw:http://www.danimahosting.com/support/");
subItems[14][3] = new Array("Your Control Panel", "windw:http://www.danimahosting.com/members/");
//subItems[14][4] = new Array("Payment", "/webhosting/payment");
subItemCount[14] = 4;
//Professional Web Design
subItems[7][0] = new Array("Overview", "/webdesign/");
subItems[7][1] = new Array("The Process", "/webdesign/theprocess");
subItems[7][2] = new Array("Resources", "/webdesign/resources");
subItems[7][3] = new Array("Portfolio", "/ourportfolio/");
subItems[7][4] = new Array("Our Rates", "/webdesign/ourrates");
subItemCount[7] = 5;
//Domain Registration
subItems[8][0] = new Array("Registration", "/domains/");
subItems[8][1] = new Array("Choosing a Name", "/domains/choosinganame");
subItems[8][2] = new Array("Our Rates", "/domains/ourrates");
subItemCount[8] = 3;
//Systems & Solutions
subItems[9][0] = new Array("Overview", "/systems_solutions/");
subItems[9][1] = new Array("System Development", "/systems_solutions/systemdevelopment");
subItems[9][2] = new Array("Business Solutions","/systems_solutions/business_solutions");
subItems[9][3] = new Array('eStore', "/systems_solutions/store/");
subItems[9][4] = new Array("Portfolio","/ourportfolio/systems/");
subItems[9][5] = new Array("Our Rates","/systems_solutions/ourrates");
subItemCount[9] = 6;
//eCommerce Apps
subItems[10][0] = new Array("Overview","/ecommerce/");
subItems[10][1] = new Array("Our Products","/ecommerce/ourproducts");
subItems[10][2] = new Array("SSL Certificates","/ecommerce/sslcerts");
subItems[10][3] = new Array("Portfolio", "/ourportfolio/store/");
subItems[10][4] = new Array("Our Rates","/ecommerce/ourrates");
subItemCount[10] = 5;
//Print & Graphic Design
subItems[11][0] = new Array("Overview", "/print_graphic");
subItems[11][1] = new Array("Portfolio", "/print_graphic/portfolio/");
//subItems[11][1] = new Array("Logo Design", "/print_graphic/logodesign");
//subItems[11][2] = new Array("Print", "/print_graphic/printing");
//subItems[11][3] = new Array("Shopping Centres", "/print_graphic/shopping");
//subItems[11][4] = new Array("Wine Industry", "/print_graphic/wine");
subItemCount[11] = 2;
//SEO
subItems[12][0] = new Array("What Is SEO?", "/seo/whatisseo");
subItems[12][1] = new Array("SEO Packages", "/seo/seopackages");
subItems[12][2] = new Array("Social Networking", "/seo/socialnetworking");
subItems[12][3] = new Array("Tips", "/seo/tips");
subItems[12][4] = new Array("E-Marketing Resources", "/seo/emarketingresources");
subItemCount[12] = 5;
//Danima Resource Center thing
subItems[13][0] = new Array("Library", "/resources/");
subItems[13][1] = new Array("Support Tickets", "/resources/support_tickets");
subItems[13][2] = new Array("Demonstrations", "/resources/demos");
subItemCount[13] = 3;
//Webproducts (only on bottom footer menu)
subItems[15][0] = new Array("Product Line", "/webproducts/products");
subItems[15][1] = new Array("System Development", "/webproducts/system");
subItems[15][2] = new Array("Request a Quote", "/webproducts/request");
subItems[15][3] = new Array("Our Rates", "/webproducts/rates");
subItemCount[15] = 4;

/* jQuery Flash replacement menu - Dave D. Sept2010
** Funky animations, all that jazz, blah blah
** Uses 3d arrays set in Items.js for the the menu and submenu items
*/

var subOnScreen = false;
var currentMenu = 0;
var defaultAlreadyRan = false;

function buildMenu() {
    var xWidth = Math.round((740 / mainItemCount) - (3*mainItemCount));
    var parent = document.getElementById('menu');
    for(var i=0; i < mainItemCount; i++) {
        var newItem = document.createElement('div');
        newItem.className = 'item';
        newItem.style.width = xWidth + 'px';
        if(mainItems[i] == 'Home') {
            newItem.innerHTML = '<a href="/" class="main_link a' + i + '" rel="' + i + '">' + mainItems[i] + '</a>';
        } else if(mainItems[i] == "Request Quote") {
            newItem.innerHTML = '<a href="/webproducts/request/" class="main_link a' + i + '">' + mainItems[i] + '</a>';
        } else {
            newItem.innerHTML = '<a href="javascript:void(0)" class="main_link a' + i + '" rel="' + i + '">' + mainItems[i] + '</a>';
        }
        parent.appendChild(newItem);
    }
    //This binds a click event to each link tag above
    $('#menu > [class=item]').hover(function() {
            $(this).animate({
                backgroundPosition: '0px 0px'
            }, 400);
        },function() {
            $(this).animate({
                backgroundPosition: '-200px 0px'
            }, 400);
    });
    $('a[class*=main_link]').click(function() {
        $(this).parent().unbind('mouseleave');
        if(subOnScreen) {
            $('[class=item]').animate({
                'borderBottomWidth' : 1,
                'borderTopWidth' : 0
            });
            clearSubMenu();
        }
        $(this).parent().animate({
            'borderBottomWidth': 0,
            'borderTopWidth': 5
        }, 500);
        currentMenu = $(this).attr('rel');
        buildSubMenu($(this).attr('rel'));
    });
}
function buildSubMenu(primary) {
    //Animate the stuff coming on the screen, selecting the primary menu, etc.
    var parent = document.getElementById('submenu');
    var count = subItemCount[primary];
    for(var i = 0; i < count; i++) {
        var x = subItems[primary][i][1];
        if(x.indexOf("modal:") > -1) {
            var temp = x.substring(6, x.length);
            var newItem = $('<div class="item" rel="sItem' + primary + '" style="margin-left: 899px;"><a class="sub_link modal_box" href="' + temp + '">' + subItems[primary][i][0] + '</a>&nbsp;&nbsp;<span style="border-right: 1px solid #FF9D04;">&nbsp;</span></div>');
        } else if(x.indexOf("windw:") > -1) {
            var temp = x.substring(6, x.length);
            var newItem = $('<div class="item" rel="sItem' + submenu + '" style="margin-left: 899px;"><a class="sub_link" target="_blank" href="' + temp + '">' + subItems[submenu][i][0] + '</a>&nbsp;&nbsp;<span style="border-right: 1px solid #FF9D04;">&nbsp;</span></div>');
        } else {                                                                                    
            var newItem = $('<div class="item" rel="sItem' + primary + '" style="margin-left: 899px;"><a class="sub_link" href="' + subItems[primary][i][1] + '">' + subItems[primary][i][0] + '</a>&nbsp;&nbsp;<span style="border-right: 1px solid #FF9D04;">&nbsp;</span></div>');
        }
        $('#submenu').append(newItem);
    }
    var $string = 'div[rel*=sItem' + currentMenu + ']';
    animateSubMenu($string);
    subOnScreen = true;
}

function defaultSubMenu(submenu) {
    //Animate the stuff coming on the screen, selecting the primary menu, etc.
    var parent = document.getElementById('submenu');
    var count = subItemCount[submenu];
    for(var i = 0; i < count; i++) {
        var x = subItems[submenu][i][1];
        if(x.indexOf("modal:") > -1) {
            var temp = x.substring(6, x.length);
            var newItem = $('<div class="item" rel="sItem' + submenu + '" style="margin-left: 899px;"><a class="sub_link modal_box" href="' + temp + '">' + subItems[submenu][i][0] + '</a>&nbsp;&nbsp;<span style="border-right: 1px solid #FF9D04;">&nbsp;</span></div>');
        } else if(x.indexOf("windw:") > -1) {
            var temp = x.substring(6, x.length);
            var newItem = $('<div class="item" rel="sItem' + submenu + '" style="margin-left: 899px;"><a class="sub_link" target="_blank" href="' + temp + '">' + subItems[submenu][i][0] + '</a>&nbsp;&nbsp;<span style="border-right: 1px solid #FF9D04;">&nbsp;</span></div>');
        } else {
            var newItem = $('<div class="item" rel="sItem' + submenu + '" style="margin-left: 899px;"><a class="sub_link" href="' + subItems[submenu][i][1] + '">' + subItems[submenu][i][0] + '</a>&nbsp;&nbsp;<span style="border-right: 1px solid #FF9D04;">&nbsp;</span></div>');
        }
        $('#submenu').append(newItem);
    }
    var $string = 'div[rel*=sItem' + submenu + ']';
    animateSubMenu($string);
    subOnScreen = true;
}

function clearSubMenu() {
    //This binds a click event to each link tag above
    $('a[class*=a' + currentMenu + ']').parent().unbind().css('background-position','200px 0px');
    $('a[class*=a' + currentMenu + ']').parent().hover(function() {
            $(this).animate({
                backgroundPosition: '0px 0px'
            }, 400);
        },function() {
            $(this).animate({
                backgroundPosition: '-200px 0px'
            }, 400);
    });
    /*$('#submenu').animate({
        'backgroundPosition':'-750px 0px'
    }, 750)*/
    $('div[rel*=sItem' + currentMenu + ']').animate({
        'paddingTop': 100,
        'marginLeft': '-300'
    },1500, function() { $(this).remove(); });
}

function animateSubMenu(node) {
    $('#submenu').animate({
        'backgroundPosition': '0px 0px'
    }, 1200);
    $(node).animate({
        "marginLeft":"0px"
    }, 1200);
}

$(document).ready(function() {   
    if(defaultAlreadyRan== false) {
        if(currentSub != '') {
            defaultSubMenu(currentSub);
            currentMenu = currentSub;
        }
        buildMenu();
        defaultAlreadyRan = true;
        $('[class=item]').css('background-position', '-200px 0px');
    }
    
    $('a[class*=modal_box]').click(function() {
        $(this).colorbox({innerWidth: 700, innerHeight: 300});
    });
});
