﻿
jQuery.fn.extend({
    rollover: function () {//plugins creation
        return this.each(function () {
            var pth = $(this).find("img")[0];
            $(this).hover(function () {
                var rolloverid = $(this).attr("id");
                removeOver();
                //                $('#main-photo').css("background-image", "url(/images/main-photo-" + rolloverid + ".jpg)");
                //$(pth).attr("src", pth.src.replace(/.jpg/g, '-over.jpg')); // mouse over Image
                var content = "";
                var contentTitle = "";
                var imgRollover = '';

                switch (rolloverid) {
                    case 'td1':
                        content = '<p>Trade Credit Insurance is an insurance product that protects against the risk of non payment of a trade account receivable.  A Trade Credit Insurance policy indemnifies the policyholder for the amount of ...</p><a href="eia-trade-credit-insurance.html">Read more</a>';
                        contentTitle = 'Trade Confidently in an Unstable World';
                        imgRollover = '/images/trade-home.jpg';
                        break;
                    case 'td2':
                        content = '<p>When operating in Emerging Markets, your assets and investments are often not properly protected by your standard Property & Casualty policies. Political Risk Insurance products are designed to ...</p><a href="eia-political-risk-insurance.html">Read more</a>';
                        contentTitle = 'Mitigate the Risk of Hostile Political Events';
                        imgRollover = '/images/political-home.jpg';
                        break;
                }

                $('#info-box').html(content);
                $('#address').html(contentTitle);
                $('#imgRollover').attr("src", imgRollover);
                $('#imgRollover').show();
                hideFlash();

            }, function () {
                //$('#main-photo').css("background-image", "url(/images/main-photo.jpg)");
                //                var content = '<h1>A Business Cash Advance Can Help You Succeed</h1><h2>Express Working Capital—Partnering for Success</h2><p>Operating a business in today’s financial climate isn’t easy. The recent credit crunch makes it difficult, at best, to get the capital you need to operate and grow your business.</p><div id="btnReadMore"></div>';
                //                $('#info-box').html(content);
            });
        });
    }
});


function hideFlash() {
    f = document.getElementsByTagName('object');
    for (var i = 0; i < 1; i++) {
        f[i].style.cssText = 'display:none';
    }
}

function showFlash() {
    f = document.getElementsByTagName('object');
    for (var i = 0; i < 1; i++) {
        f[i].style.cssText = 'display:block';
        }
}


function removeOver() {
    $('#1').attr("src", '/images/menu-this-works.jpg'); // mouse out image
    $('#2').attr("src", '/images/menu-do-i-qualify.jpg'); // mouse out image
    $('#3').attr("src", '/images/menu-much-capital.jpg'); // mouse out image
    $('#4').attr("src", '/images/menu-do-i-apply.jpg'); // mouse out image
    $('#5').attr("src", '/images/menu-do-i-learn-more.jpg'); // mouse out image    
}

$(document).ready(function () {
    // show / hide menu
    $('ul li:has(ul)').hover(
            function (e) {
                $(this).find('ul').slideDown();
                $(this).css('background-color', '#27448b');
            },
            function (e) {
                $(this).find('ul').slideUp();
                $(this).css('background-color', '#e6b85d');
            }
            );

    $('#root > li').hover(
        function (e) {
            $(this).find('a').first().css('background-color', '#f3d63f');
        },
        function (e) {
            $(this).find('a').first().css('background-color', '#27448b');
        }
    );

    $('#main-photo').mouseleave(function () {
        //        $('#main-photo').css("background-image", "url(/images/main-home.jpg)");
        var content = '<p>Established in 1979, EIA Global has a staff with more extensive knowledge and expertise in Trade Credit and Political Risk Insurance than any other broker in the world. Our unrivaled team of accomplished and skilled ...</p><a href="why-eia-global.html">Read more</a></div>';
        $('#info-box').html(content);
        var contentTitle = 'Protecting Clients’ Assets for over 30 Years';
        $('#address').html(contentTitle);
        //var imgRollover = '/images/main-home.jpg';
        //$('#imgRollover').attr("src", imgRollover);
        $('#imgRollover').hide();
        showFlash();
        removeOver();
    });

    $("#menu ul li").rollover(); // call the function

});
