// tabs switcher code
function initTabs(){
    $('.tabset').each(function()
    {
        var _tablinks = $(this).find('a.tab');
        _tablinks.each(function(){
            _curtab = $(this).attr('href');
            if($(_curtab).length) {
                $(_curtab).addClass('inactive').removeClass('active').css('display', 'none');
                if($(this).hasClass('active')) $(_curtab).addClass('active').css('display', 'block');
            }

            $(this).hover(
                function(){
                    _url = $(this).attr('href');
                    _tablinks.each(function() {
                        $($(this).attr('href')).removeClass("active").addClass("inactive").css({'display' : 'none', 'opacity' : '0'});
                        $(this).removeClass('active');
                        $(this).parent().removeClass("hover");
                    });

                    $(this).parent().addClass("hover");
                    $(_url).removeClass("inactive").addClass("active").css({'display' : 'block', 'opacity' : '1'});
                    $(this).addClass('active');
                    return false;
                },
                function(){return false;}
            );
        });
    });
}

// side menu code
function initMenu() {
    $("ul.slide-menu li").each(function(){
        var _this = $(this);
        _this._sliding = false;

        $(this).hover(
            function() {
                if(_this._sliding) return false;
                if($(this).find(".slide").hasClass("active")) return false;
                _this._sliding = true;
                $(".slide-menu .slide").removeClass("active");
                var _slider = $(this).find("div.slide").eq(0);
                if(_slider) {
                    $(this).addClass("active")
                    $(_slider).slideDown(200,function(){
                        _sliding = false;
                    });
                }
                var _image = $(this).find("img");
                if (_image)
                {
                    $(_image).toggleClass("fullLeftImage").toggleClass("clippedLeftImage");
                }
            },
            function() {
                _this = $(this);
                var _int;
                _int = setInterval(function(){
                    if(!_this._sliding){
                        clearTimeout(_int);
                        var _slider = $(_this).find("div.slide").eq(0);
                        if(_slider) {
                            $(_this).removeClass("active")
                            $(_slider).slideUp(100);
                        }
                        var _image = $(this).find("img");
                        if (_image)
                        {
                            $(_image).toggleClass("fullLeftImage").toggleClass("clippedLeftImage");
                        }
                    }
                },200);
            }
        );
    });
}

// page init code
$(document).ready(function(){
    initTabs();
    initMenu();
    
    var homeImage = $("img[src*='/images/home.gif']");
    
    if (homeImage.length > 0)
    {
        homeImage.height(13).width(13);
    }
    
    var recaptchaImgDiv = $("#recaptcha_logo");
    
    if (recaptchaImgDiv.length > 0)
    {
        if (location.protocol.indexOf("https:") >= 0)
        {
            recaptchaImgDiv.attr("src","https://api-secure.recaptcha.net/img/clean/logo.gif");
        }
        else
        {
            recaptchaImgDiv.attr("src","http://api.recaptcha.net/img/clean/logo.gif");
        }
    }
    
    var recaptchaTagLineDiv = $("#recaptcha_tagline");
    
    if (recaptchaTagLineDiv.length > 0)
    {
        if (location.protocol.indexOf("https:") >= 0)
        {
            recaptchaTagLineDiv.attr("src","https://api-secure.recaptcha.net//img/clean/tagline.gif");
        }
        else
        {
            recaptchaTagLineDiv.attr("src","http://api.recaptcha.net//img/clean/tagline.gif");
        }
    }
});

$(
    function()
    {
        $('#gallery a').lightBox();
    }
);

var divCode = "<div id='{myPlayerGoesHereId}'><a href='http://www.adobe.com/go/getflashplayer'><img src='http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif' alt='Get Adobe Flash player' /></a></div>";

var ConvertImagesToMovies = function ()
{
    var counter = 0;
    var flashIcons = $("#flashIcon");
    if (flashIcons.length > 0)
    {
        flashIcons.each(function ()
        {
            counter = counter + 1;

            var flashValue = $(this).attr('title');

            var values = flashValue.split("~~");
            if (values.length > 0)
            {
                var newUrl = values[0];

                //var newObjectCode = objectCode.replace("{0}", newUrl);
                var myPlayerId = 'myPlayer' + counter;
                var myPlayerGoesHereId = 'myPlayerGoesHere' + counter;
                var newDivCode = divCode.replace('{myPlayerGoesHereId}', myPlayerGoesHereId);

                $(this).before(newDivCode);
                $(this).remove();
                $("#videoToReplace").replaceWith(newDivCode);

                var flashvars = { src: newUrl, autostart: 'true', themeColor: '0395d3', mode: 'overlay', scaleMode: 'fit', frameColor: '333333', fontColor: 'cccccc', link: '', embed: '' };
                var params = { allowFullScreen: 'true' };
                var attributes = { id: myPlayerId, name: myPlayerId };
                swfobject.embedSWF('/javascript/thirdparty/AkamaiFlashPlayer.swf', myPlayerGoesHereId, values[2], values[1], '9.0.0', '/javascript/thirdparty/expressInstall.swf', flashvars, params, attributes);
            }
        });
    }
};