﻿function insertTracking() {
    pageTracker._trackEvent('HomePageFeatureEngine', 'Click', 'PartnersAtTheMoment');
}


//On Page Load
$(document).ready(function() {
    /*Home Page flash banenr - call function from global.js*/
    home_flash2();
    //$('#area').html('<a href="http://www.socializationofdata.com/partners-at-the-moment/" onClick="insertTracking();"><img src="images/home/partner_banner.jpg" alt="Partners at the Moment"/></a>');
    page.init();
    //Function to update logos
    $('#logos li:eq(0)').show();
    setInterval("update_logo()", 3580);
});  //jQuery On Page Load

(function($) {
    $.fn.fadeTransition = function(options) {
        // var options = $.extend({ pauseTime: null, transitionTime: null }, options);
        var transitionObject;

        Trans = function(obj) {
            var timer = null;
            var current = 0;
            var els = $("> *", obj).css("display", "none").css("left", "0").css("top", "0").css("position", "absolute");
            $(obj).css("position", "relative");
            $(els[current]).css("display", "block");

            function transition(next) {
                $(els[current]).fadeOut();
                $(els[next]).fadeIn();
                current = next;
                cue();
            };

            function cue() {
                if ($("> *", obj).length < 2) return false;
                //if (timer) clearTimeout(timer);
                //timer = setTimeout(function() { transition((current + 1) % els.length | 0) }, options.pauseTime);
            };

            this.showItem = function(item) {
                if (timer) clearTimeout(timer);
                transition(item);
            };

            cue();
        }
        this.showItem = function(item) {
            transitionObject.showItem(item);
        };

        return this.each(function() {
            transitionObject = new Trans(this);
        });
    }
})(jQuery);

var page = {
    tr: null,
    init: function() {
        $("div.navigation").each(function() {

            // alert($(this).parent().get(0).id);


            //$("div.navigation").parent().css('background-color','red');

            $("div.rotator.r2").hide();
            $("div.rotator.r3").hide();
            $("div.rotator.r4").hide();
            $(this).children().each(function(idx) {
                if ($(this).is("a"))
                    $(this).click(function() {
                        var ids = $(this).get(0).id;
                        //alert($(this).get(0).id);
                        switch (ids) {
                            case "sr1":
                                SelectVideoHolder("div.rotator.r1");
                                break;
                            case "sr2":
                                SelectVideoHolder("div.rotator.r2");
                                break;
                            case "sr3":
                                SelectVideoHolder("div.rotator.r3");
                                break;
                            case "sr4":
                                SelectVideoHolder("div.rotator.r4");
                                break;
                                
                                




                        }
                       
                    }

                )
            });
        });

    },
    show: function(idx) {
        alert(idx);
        //if (page.tr.timer) clearTimeout(page.tr.timer);
        page.tr.showItem(idx);
    }




};



function SelectVideoHolder(id) {
    $("div.rotator.r1").hide();
    $("div.rotator.r2").hide();
    $("div.rotator.r3").hide();
    $("div.rotator.r4").hide();

    $(id).fadeIn("slow"); 



}

//Customers Logos animation
var index = 0;
var old_index;
var current;
var next;
var imgwidth;
function update_logo() {
    old_index = index;
    current = '#logos li:eq(' + old_index + ')';
    while (old_index == index) {//Ensure change of logo
        index = Math.ceil(Math.random() * 9); //Random element from 0 - 9
    }
    next = '#logos li:eq(' + index + ')';
    $(current).hide();
    $(next).show();
}
