$(document).ready(function () {

    $("#worldwidelinks ul").html("");
    $("<li><a href='http://www.sabinsa.com.au/'>Australia - English</a></li>").appendTo("#worldwidelinks ul");
    $("<li><a href='http://www.sabinsa.com.cn/'>China - Chinese</a></li>").appendTo("#worldwidelinks ul");
    $("<li><a href='http://www.sabinsaeurope.com/'>Europe - English</a></li>").appendTo("#worldwidelinks ul");
    $("<li><a href='http://www.sabinsaeurope.com/de/'>Europe - German</a></li>").appendTo("#worldwidelinks ul");
    $("<li><a href='http://www.sabinsa.co.jp/'>Japan - Japanese</a></li>").appendTo("#worldwidelinks ul");
    $("<li><a href='http://www.hanburyfze.com/'>UAE - English</a></li>").appendTo("#worldwidelinks ul");
    $("<li><a href='http://www.sabinsa.com/'>USA - English</a></li>").appendTo("#worldwidelinks ul");

    $("#menu1").html(""); /* About Us - Populate Sub-menus */
    $("<li><a href='/our-story.html'>Our Story</a></li>").appendTo("#menu1");
    $("<li><a href='/our-people.html'>Our People</a></li>").appendTo("#menu1");
    $("<li><a href='/milestones/'>Milestones</a></li>").appendTo("#menu1");
    $("<li><a href='/manufacturing-facilities.html'>Manufacturing Facilities</a></li>").appendTo("#menu1");
    $("<li><a href='/research-development.html'>Research &amp; Development</a></li>").appendTo("#menu1");
    $("<li><a href='/patents/'>Intellectual Properties</a></li>").appendTo("#menu1");
    $("<li><a href='/awards/'>Awards</a></li>").appendTo("#menu1");
    $("<li><a href='/associated-companies.html'>Associated Companies</a></li>").appendTo("#menu1");

    $("#menu2").html(""); /* Products & Services - Populate Sub-menus */
    $("<li><a href='/products/natural-drugs/'>Natural Drugs</a></li>").appendTo("#menu2");
    $("<li><a href='/products/standardized-phytoextracts/'>Standardized Phytoextracts </a></li>").appendTo("#menu2");
    $("<li><a href='/products/scfe/'>SCFE Products </a></li>").appendTo("#menu2");
    $("<li><a href='/products/enzymes/'>Enzymes</a></li>").appendTo("#menu2");
    $("<li><a href='/products/probiotics-synbiotics/'>Probiotics &amp; Synbiotics </a></li>").appendTo("#menu2");
    $("<li><a href='/products/beverage-ingredients/'>Beverage Ingredients </a></li>").appendTo("#menu2");
    $("<li><a href='/products/functional-nutritional-blends/'>Functional Nutritional Blends </a></li>").appendTo("#menu2");
    $("<li><a href='/products/specialty-fine-chemicals/'>Specialty Fine Chemicals</a></li>").appendTo("#menu2");
    $("<li><a href='/products/nutritional-fine-chemicals/'>Nutritional Fine Chemicals</a></li>").appendTo("#menu2");
    $("<li><a href='/products/chiral-drug-intermediates/'>Chiral Drug Intermediates</a></li>").appendTo("#menu2");
    $("<li><a href='/products/nutritional-fibers/'>Nutritional Fibers</a></li>").appendTo("#menu2");
    $("<li><a href='/products/minerals/'>Minerals for Nutritional Use</a></li>").appendTo("#menu2");
    $("<li><a href='/products/cosmeceuticals/'>Cosmeceuticals</a></li>").appendTo("#menu2");
    $("<li><a href='/products/aquasol/'>AquaSol Ingredients</a></li>").appendTo("#menu2");
    $("<li><a href='/products/gras/'>GRAS Affirmed Ingredients</a></li>").appendTo("#menu2");
    $("<li><a href='/services/research/'>Contract Research</a></li>").appendTo("#menu2");
    $("<li><a href='/services/farming/'>Contract Farming</a></li>").appendTo("#menu2");

    $("#menu3").html(""); /* Newsroom - Populate Sub-menus */
    $("<li><a href='/newsroom/press-releases/'>Press Releases</a></li>").appendTo("#menu3");
    $("<li><a href='/newsroom/exhibitions-fairs.html'>Exhibitions &amp; Fairs</a></li>").appendTo("#menu3");

    $("#menu4").html(""); /* Contact Us - Populate Sub-menus */
    $("<li><a href='/contact/'>Contact Sami Labs</a></li>").appendTo("#menu4");
    $("<li><a href='/contact/international/'>International Presence</a></li>").appendTo("#menu4");
    $("<li><a href='/contact/join-samilabs.html'>Join Sami Labs</a></li>").appendTo("#menu4");

    $("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
    $("ul.topnav li a").mouseover(function () { //When trigger is clicked...
        //Following events are applied to the subnav itself (moving subnav up and down)
        $(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
        $(this).parent().hover(function () {
        }, function () {
            $(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
        });
        //Following events are applied to the trigger (Hover events for the trigger)
    }).hover(function () {
        $(this).addClass("subhover"); //On hover over, add class "subhover"
    }, function () {  //On Hover Out
        $(this).removeClass("subhover"); //On hover out, remove class "subhover"
    });

    $(".tab_content").hide(); //Hide all content
    $("#tabnewsevents > ul.tabs > li:first").addClass("active").show(); //Activate first tab
    $("#tabnewsevents > ul.tabs > li:first > a > span:even").removeClass("headingcolor1");
    $("#tabnewsevents > ul.tabs > li:first > a > span:odd").removeClass("headingcolor2");
    $("#tabnewsevents .tab_content:first").show(); //Show first tab content
    $("#tabawardspatents > ul.tabs > li:first").addClass("active").show(); //Activate first tab
    $("#tabawardspatents > ul.tabs > li:first > a > span:even").removeClass("headingcolor1");
    $("#tabawardspatents > ul.tabs > li:first > a > span:odd").removeClass("headingcolor2");
    $("#tabawardspatents .tab_content:first").show(); //Show first tab content

    //On Click Event
    $("#tabnewsevents > ul.tabs > li").click(function () {

        if (!$(this).hasClass("active")) {
            $("#tabnewsevents > ul.tabs > li").removeClass("active"); //Remove any "active" class
            $(this).addClass("active"); //Add "active" class to selected tab
            $("#tabnewsevents .tab_content").hide(); //Hide all tab content
            $("#tabnewsevents > ul.tabs > li > a > span:even").toggleClass("headingcolor1");
            $("#tabnewsevents > ul.tabs > li > a > span:odd").toggleClass("headingcolor2");

            var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
            $(activeTab).fadeIn(); //Fade in the active ID content
        }
        return false;
    });

    //On Click Event
    $("#tabawardspatents > ul.tabs > li").click(function () {

        if (!$(this).hasClass("active")) {
            $("#tabawardspatents > ul.tabs > li").removeClass("active"); //Remove any "active" class
            $(this).addClass("active"); //Add "active" class to selected tab
            $("#tabawardspatents .tab_content").hide(); //Hide all tab content
            $("#tabawardspatents > ul.tabs > li > a > span:even").toggleClass("headingcolor1");
            $("#tabawardspatents > ul.tabs > li > a > span:odd").toggleClass("headingcolor2");

            var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
            $(activeTab).fadeIn(); //Fade in the active ID content
        }
        return false;
    });


});

function openNewsLetter() {
    var dest = document.getElementById('opt_newsletter').selectedIndex;
    window.open(document.getElementById('opt_newsletter').options[dest].value, target = "_self");
}

