// JavaScript Document
jQuery(document).ready(function() {

    //	//VERTICAL CAROUSEL SCRIPT END
    jQuery('#mycarousel').jcarousel({
        vertical: true,
        scroll: 1
    });
    //VERTICAL CAROUSEL SCRIPT START

    //BANNER SCRIPT START
    // run the code in the markup!
    $('table pre code').not('#skip,#skip2').each(function() {
        eval($(this).text());
    });

    $('#s4').before('<div id="nav" class="nav">').cycle({
        fx: 'fade',
        speed: 'slow',
        timeout: 5000,
        pager: '#nav'
    });
    //BANNER SCRIPT END

    //NAVIGATION SCRIPT START
    function megaHoverOver() {

        $(this).find(".sub").stop().fadeTo('fast', 1).show();

        //Calculate width of all ul's
        (function($) {
            jQuery.fn.calcSubWidth = function() {
                rowWidth = 0;
                //Calculate row
                $(this).find("ul").each(function() {
                    rowWidth += $(this).width();
                });
            };
        })(jQuery);

        if ($(this).find(".row").length > 0) { //If row exists...
            var biggestRow = 0;
            //Calculate each row
            $(this).find(".row").each(function() {
                $(this).calcSubWidth();
                //Find biggest row
                if (rowWidth > biggestRow) {
                    biggestRow = rowWidth;
                }
            });
            //Set width
            $(this).find(".sub").css({ 'width': biggestRow });
            $(this).find(".row:last").css({ 'margin': '0' });

        } else { //If row does not exist...

            $(this).calcSubWidth();
            //Set Width
            $(this).find(".sub").css({ 'width': rowWidth });

        }
    }

    function megaHoverOut() {
        $(this).find(".sub").stop().fadeTo('fast', 0, function() {
            $(this).hide();
        });
    }


    var config = {
        sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
        interval: 60, // number = milliseconds for onMouseOver polling interval    
        over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
        timeout: 50, // number = milliseconds delay before onMouseOut    
        out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
    };

    $("ul#topnav li .sub").css({ 'opacity': '0' });
    $("ul#topnav li").hoverIntent(config);
    //NAVIGATION SCRIPT END

    //MODAL SCRIPT START NAVIGATION
    //jQuery(function ($) {
    //	$('#basic-modal .basic').click(function (e) {
    //	$('#basic-modal-content').modal();

    //		  return false;
    //	});
    //MODAL SCRIPT END		


    //MODAL SCRIPT START
    jQuery(function($) {
        $('.modalButton').click(function(e) {
            $('#basic-modal-content').modal();
            return false;
        });
        //MODAL SCRIPT END 


        // DROP SELECT MENU START
        $(document).ready(function() {

            $('.DropSelectMenu').each(function(e) { $(this).sSelect({ ddMaxHeight: '400px' }); });

            //set max height
            $('#my-dropdownCountries').sSelect({ ddMaxHeight: '300px' });

            //set value on click
            $('#setVal').click(function() {
                $('#my-dropdown5').getSetSSValue('4');
            });

            //get value on click
            $('#getVal').click(function() {
                alert('The value is: ' + $('#my-dropdown5').getSetSSValue());
            });

            //alert change event
            $('#my-dropdownChange').sSelect().change(function() { alert('changed') });

            //add options to select and update
            $('#addOptions').click(function() {
                $('#my-dropdown6').append('<option value="newOpt">New Option</option>').resetSS();
                return false;
            });

        });

        // DROP SELECT MENU END

        //JUMP TO PRODUCTS BOOKMARK                
        $(document).ready(function() {
            //add an additional class selector incase this ID is used elsewhere in the templates            
            $('div.BROWSE-HOME select#my-dropdown2').change(function() {		
                var query = $(this).val();		
                setTimeout(function(){
			        window.location = "/products.html#" + query;		
			    }, 0);		 
			    return false;	        
			});                
		});
		
		$(document).ready(function() { //equivalent to window.onload            
            $('div.BROWSE-HOME select#my-dropdown').change(function() { 		
                var query = $(this).val();		
                setTimeout(function(){			
                    window.location = "/products/databases.aspx?subj=" + query;		
                }, 0);
                return false;            
            });                
        });                        //Informit Indexes Select options                
        
        $(document).ready(function() {                        
            $('div.DROP-MENU div.MenuType1 select').change(function() {                
                var query = $(this).val();			
                setTimeout(function(){				
                    window.location = "/indexes_" + query + ".html";	
	            }, 0);                    
	            return false;                                                        
			});                
	    });                
	    
        // EXPAND CONTENT START

        $(document).ready(function() {

            $(".collapsableDiv").hide();

            $(".toggler").click(function() {

                //fixes to work with className rather than id
                //var collapsableDivId = '#' + $(this).attr('id').replace('tg', 'cd');

                //$(collapsableDivId).slideToggle("slow", function () {
                $(this).prev('div.collapsableDiv').slideToggle("slow", function() {
                    //var togglerId = '#' + $(this).attr('id').replace('cd', 'tg');
                    var toggleLink = $(this).next('div.toggler');

                    if ($(this).css('display') == 'none') {
                        $(toggleLink).html("Expand to see full list");
                        $(toggleLink).addClass("togglerCollapsed");
                        $(toggleLink).removeClass("togglerExpanded");
                    }
                    else {
                        $(toggleLink).html("Close list");
                        $(toggleLink).addClass("togglerExpanded");
                        $(toggleLink).removeClass("togglerCollapsed");
                    }
                });
            });

            //EXPANDER SCRIPT START - TEMPLATE F and G
            $("a.accordion_bar").click(function() {
                $(this).next().slideToggle("slow", accordionBarToggle);
                return false;
            }).next().hide();
            $("a.accordion_toggler").click(function() {
                $(this).parent().slideToggle("slow", accordionBarToggle);
            });
            $("a.accordion_expand_all").click(function() {
                $(this).parent().find('div.accordion_content:not(:visible)').slideToggle("slow", accordionBarToggle);
            });
            $("a.accordion_collapse_all").click(function() {
                $(this).parent().find('div.accordion_content:visible').slideToggle("slow", accordionBarToggle);
            });
            function accordionBarToggle() {
                var isCollapsed = $(this).is(':hidden');
                if (isCollapsed) {
                    $(this).prev().addClass("accordion_bar_collapsed");
                    $(this).prev().removeClass("accordion_bar_expanded");
                }
                else {
                    $(this).prev().addClass("accordion_bar_expanded");
                    $(this).prev().removeClass("accordion_bar_collapsed");
                }
            }
            //EXPANDER SCRIPT END


        });
        // EXPAND CONTENT END


    });

});

