﻿function showProductRotatorLink(selector) {
	$(selector).stop(true, true).animate({ opacity: 1 }, 250);
}
function hideProductRotatorLink(selector) {
	$(selector).stop(true, true).animate({ opacity: 0 }, 250);
}

function rotateProduct(parentselector) {
	//Get the first image
	//				var parentselector = "#product_overview";
	var current = ($(parentselector + ' div.show') ? $(parentselector + ' div.show') : $(parentselector + ' div:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ?
								((current.next().hasClass('show')) ? $(parentselector + ' div:first') : current.next())
							:
	// wenn man beim letzten item angekommen wieder von vorne beginnen
								$(parentselector + ' div:first'));

	//Set the fade in effect for the next image, the show class has higher z-index
	next.stop(true, true)
					.fadeIn(1000)
					.addClass('show');

	//Hide the current image
	current.stop(true, true)
					.fadeOut(1000)
					.removeClass('show');
}

function IndexToButtonName(prefix, index) {
    var btn = "";
    if (index == 0)
        btn = "#"+prefix+"_ema_s";
    else
        if (index == 1)
            btn = "#"+prefix+"_m2a_s";
        else
            if (index == 2)
                btn = "#"+prefix+"_p2a_s";
            else
                if (index == 3)
                    btn = "#"+prefix+"_s2a_s";
                else
                    if (index == 4)
                        btn = "#"+prefix+"_v2a_s";
                    else
                        if (index == 5)
                            btn = "#"+prefix+"_f2a_s";
                        else
                            if (index == 6)
                                btn = "#"+prefix+"_ediscovery_s";

    return btn;
}


var productTimerHandle = null;
var bannerTimerHandle = null;
var newsTimerHandle = null;

var ema_selection = 0; // standard selection "enterprise managed archive"
var cloud_selection = 0; // standard selection cloud
var outside_call = false;
$(document).ready(function () {

	// this line is for ie6 browsers to show 
	$('div#brandrotator>div:first').css({ opacity: 1 });

    // product rotator
    // erst die js version setzt eine feste höhe voraus
    $('#product_overview').css('height', '501px');

    $('div#banner_bottom div#banner_area').css('height', '129px');
    $('div#banner_bottom div#news_area').css('height', '129px');

    // ohne js wird der rotatorlink nicht angezeigen
    $('div.main_content a.rotatorlink').css('display', 'inline');


    // an den product divs soll 
    //$('#product_overview div.product').css('position', 'absolute');
    $('div.product').removeClass('noscript').addClass('script').hide();
    $('div.product:first').show(); //css({opacity: 1});

    $('div#banner_bottom div.rotatoritem').removeClass('noscript').addClass('script').hide();
    $('div#banner_bottom div#banner_area div.rotatoritem:first').addClass('show').show();
    $('div#banner_bottom div#news_area div.rotatoritem:first').addClass('show').show();



    // change postioning if javascript is enabled
    $('div.product div.image').removeClass('noscript2').addClass('script2');
    // show hidden blank image for image map
    $('div.product div.image img#blank').css('display', 'inline');
	$('div.product div.image img#blank2').css('display', 'inline');
	$('div.product div.image div#bt_ema_s').css('display', 'inline');
	$('div.product div.image div#cloud_ema_s').css('display', 'inline');

    $('div.product div.tabs').removeClass('noscript3').addClass('script3');




    $('div#product_overview').hover(function () {

        showProductRotatorLink('div#product_overview a.rotatorlink');
        clearInterval(productTimerHandle);
        productTimerHandle = null;
    }, function () {

        hideProductRotatorLink('div#product_overview a.rotatorlink');
        if (productTimerHandle == null)
            productTimerHandle = setInterval("rotateProduct(\'#product_overview\')", 10000);
    });
    $('#product_overview a.rotatorlink').click(function () {
        rotateProduct("#product_overview");
        return false;
    });
    productTimerHandle = setInterval("rotateProduct(\'#product_overview\')", 10000);

    if ($('div#banner_area div.rotatoritem').length > 1) {
        $('div#banner_area').hover(function () {
            showProductRotatorLink('div#banner_area a.rotatorlink');

            clearInterval(bannerTimerHandle);
            bannerTimerHandle = null;
        }, function () {
            hideProductRotatorLink('div#banner_area a.rotatorlink');

            if (bannerTimerHandle == null)
                bannerTimerHandle = setInterval("rotateProduct(\'div#banner_area\')", 10000);
        });
        $('div#banner_area a.rotatorlink').click(function () {
            rotateProduct("div#banner_area");
            return false;
        });
        bannerTimerHandle = setInterval("rotateProduct(\'div#banner_area\')", 10000);
    }

	if ($('div#news_area div.rotatoritem').length > 1) {
    $('div#news_area').hover(function () {
        showProductRotatorLink('div#news_area a.rotatorlink');

        clearInterval(newsTimerHandle);
        newsTimerHandle = null;
    }, function () {
        hideProductRotatorLink('div#news_area a.rotatorlink');

        if (newsTimerHandle == null)
            newsTimerHandle = setInterval("rotateProduct(\'div#news_area\')", 10000);
    });
    $('div#news_area a.rotatorlink').click(function () {
        rotateProduct("div#news_area");
        return false;
    });
    newsTimerHandle = setInterval("rotateProduct(\'div#news_area\')", 10000);
	}




    $("#ema_area_0, #ema_area_1, #ema_area_2, #ema_area_3, #ema_area_4, #ema_area_5, #ema_area_6").hover(function () {

        var old_selection = ema_selection;

        // get index of new button
        var area_id = $(this).attr('id');
        ema_selection = area_id.replace(/ema_area_/g, '');

        if (ema_selection != old_selection) {
            // deselect old button
            $(IndexToButtonName("bt",old_selection)).hide();

            // select new button
            var bt_id = IndexToButtonName("bt",ema_selection);
            $(bt_id).show();

            // select new tab
            outside_call = true;
            $('div.tabs').tabs('select', parseInt(ema_selection));
            outside_call = false;
        }

    }, function () {
    });


	$("#cloud_area_0, #cloud_area_1, #cloud_area_2, #cloud_area_3, #cloud_area_4, #cloud_area_5, #cloud_area_6").hover(function () {

		var old_selection = cloud_selection;

		// get index of new button
		var area_id = $(this).attr('id');
		cloud_selection = area_id.replace(/cloud_area_/g, '');

		if (cloud_selection != old_selection) {
			// deselect old button
			$(IndexToButtonName("cloud", old_selection)).hide();

			// select new button
			var bt_id = IndexToButtonName("cloud", cloud_selection);
			$(bt_id).show();

			// select new tab
			outside_call = true;
			$('div.tabs').tabs('select', parseInt(cloud_selection));
			outside_call = false;
		}


	}, function () {
	});


	// Tabs 
	$('div.tabs').tabs({
		event: 'mouseover',
		select: function (event, ui) {
			if (outside_call)
				return true;

			var substr = ui.panel['id'].substr(0, 10);
			if (substr == "enterprise") {
				var old_selection = ema_selection;

				ema_selection = ui.index;

				if (ema_selection != old_selection) {
					// deselect old button
					$(IndexToButtonName("bt",old_selection)).hide();

					// select new button
					var bt_id = IndexToButtonName("bt",ema_selection);
					$(bt_id).show();

					return true;
				}
			}

			substr = ui.panel['id'].substr(0, 5);
			if (substr == "cloud") {
				var old_selection = cloud_selection;

				cloud_selection = ui.index;

				if (cloud_selection != old_selection) {
					// deselect old button
					$(IndexToButtonName("cloud",old_selection)).hide();

					// select new button
					var bt_id = IndexToButtonName("cloud",cloud_selection);
					$(bt_id).show();

					return true;
				}				
			}
		}
	});


	if ($.browser.msie && $.browser.version == "6.0") {
		var products = $('div.product');
		var i;
		for (i = 0; i < products.length; i++)
			rotateProduct('#product_overview');
	}

});
