var caseflash = '';
var container = '';
var lastTabNodeId = 0;
var maxtab = 16;
var slider = 0;
var addthis_config;


$(document).ready(function(){
   //initSiteAccess();
    var ezu = new ezp_update();
    ezu.initSite();
   
});

function ezp_update() {

    var overlaysource = '';
	var subbranchid = '0';
    var setLastTabNodeId = false;
    var overlay_api = '';
    var active_downloadtab = '';
    container = this;

// communication flash @dho (load case)
    this.caseFlashHandler = function(nodeid) {
        $("#datastore").data("case", {slider: true});
        container.getData('case','thecase',nodeid);
    },

// load js div scroller @dho
    this.loadjScrollPane = function() {
      //  $('#case-summary').jScrollPane({showArrows:true,scrollbarWidth:8});
    },

// init Partnerslider
    this.initPartner = function(ajax) {
        if(ajax == false) {
            $("#partners-list").hide();
            $("#partners-slider-block").show();
            $(".partner-filter[name='country']").hide();
            $(".partner-filter").change(function() {
                if($(".partner-filter[name='branch']").val() == 0) {
                    $(".partner-filter[name='country']").hide(); 
                } else {
                    $(".partner-filter[name='country']").show(); 
                }
                container.getData('partner', 'filter', $('.partner-filter option:selected'));
            });
        }

        var slider = $("#partners-slider .items-holder").scrollable({
            api: true,
            speed: 700,
            size: 3,
            hoverClass: 'active',
            onSeek: function() {
                container.setPageSlider(this);
            }
         });
         if(slider)
            container.setPageSlider(slider);
        
        $(".partner-details").click(function() {
            container.getData('partner', 'detail', $(this).attr('nodeid'));
			$.scrollTo($('#partners-slider-block'), 2000);
        }).hover(function() {
            $(this).css('cursor','pointer');
        });
    },

// build Infoboxes

    this.initInfoboxes = function() {
        this.setInfoboxes('#infoboxes-bottom-4 .infoboxes-bottom-accordion', 720, 178, 160, 240);
        this.setInfoboxes('#infoboxes-bottom-5 .infoboxes-bottom-accordion', 980, 178, 184, 244);
        this.setInfoboxes('#infoboxes-bottom-6 .infoboxes-bottom-accordion', 980, 178, 147, 245);

        /*$('ul.infoboxes-bottom-accordion li.active').click(function(){
		alert('hurra');
		var url = $('ul.infoboxes-bottom-accordion li.active a').attr('href');
		if (url) {
			window.location = url;
		}
        });*/

    },

// config Infoboxes
    this.setInfoboxes = function(selector, twidth, theight, minpwidth, maxpwidth) {
        var enterFunction = function(){
            if ($(this).hasClass('first')) {
                $(this).removeClass('first');
                $(this).addClass('first-active');
            }
            if ($(this).hasClass('last')) {
                $(this).removeClass('last');
                $(this).addClass('last-active');
            }
            /*var id = $(this).attr('id');
            var url = $('#'+id+' a').attr('href');
            if (url) {
                $(this).click(function(){
                    window.location = url;
                });
            }*/
        }
        var leaveFunction = function(){
            /*$(this).unbind('click');*/
            if ($(this).hasClass('first-active')) {
                $(this).removeClass('first-active');
                $(this).addClass('first');
            }
            if ($(this).hasClass('last-active')) {
                $(this).removeClass('last-active');
                $(this).addClass('last');
            }
        }

        $(selector).hSlides({
           totalWidth: twidth,
           totalHeight: theight,
           minPanelWidth: minpwidth,
           maxPanelWidth: maxpwidth,
           activeClass: 'active',
           easing: 'easeOutQuart',
           sensitivity: 5,
           interval: 1000,
           timeout: 600,
           onEnter: enterFunction,
           onLeave: leaveFunction
        });
    },

// Reload Case Navigation
    this.loadTabNavigationController = function(target,type) {
        if(!target && !type) {
            target = $('#target_type').attr('target');
            type = $('#target_type').attr('type');
        }

        $(".case-detail-navigation a[rel=history]")
            .attr('href', function() {
              //  return '#'+ $(this).attr('href');
            }).click(function(){
                var paramcontenttype = $(this).attr('contenttype');
                lastTabNodeId = $(this).attr('nodeid');
                container.getData(target, $(this).attr('contenttype'),$(this).attr('nodeid'));
                return false;
            });
        $(".case-detail-navigation a[rel='history']").each(function() {
            if(!lastTabNodeId) {
                lastTabNodeId = $(this).attr('nodeid');
            }
            if($(this).attr('nodeid') == lastTabNodeId) {
                $(this).attr('class','active');
            } else {
                $(this).unbind('class');
            }
        });
        for(i=1;i<=maxtab;i++) {
            $('.intern-case-tab-'+i).click(function() {
                var class_string = $(this).attr('class');
                class_string = class_string.replace('intern-case-tab-','');
                class_string = class_string - 1;
                $('.case-detail-navigation a[rel=history]:eq('+class_string+')').click();
                return false;
            });
        }
        $('#intern-case-summary').click(function() {
             $('.case-detail-navigation a[contenttype=casesummary]').click();
        });
    },

// Mainnavigation
    this.initFrexibleMenu = function() {
       _holder = $("#nav");
        $(_holder).each(function(){
            _blocks = _holder.find(".drop")
            _num = _blocks.length;
            _lenght_col = $(".nav-item").eq(0).outerWidth();
            for (var i=0; i<_num; i++) {
                _cols = _blocks.eq(i).find(".nav-item");
                _numc = _cols.length;
                _length = _lenght_col * _cols.length;
                _blocks.eq(i).css({"width":_length + "px"})
            }
        });
    },
// Startpage News & Events
    this.getNewsEvents = function() {
        return setInterval(function() {
            $.ajax({
                type: "POST",
                url: "/" + $('#language-select').attr('lang') + "/ajax/startpage/",
                success: function(msg){
                    $('#startpage-news-events').css('display','none').html(msg).fadeIn(3000);
                }
            });
        }, 10000);
    },

// Ajax Basic Handler
    this.getData = function(target, type, nodeid) {
        var ajax_dataType = 'html';
        var ajax_async = false;
        if(target == 'case' || target == 'crm') {
            ajax_url = '/ajax/case/';
            if(type == 'rewrite_url') {
                ajax_dataType = 'json';
                ajax_async = true;
            } else if(type == 'extendBreadcrumb') {
				if(this.subbranchid) {
					nodeid = nodeid + '_' + this.subbranchid;
				}
			}
			ajax_url = ajax_url + target + '/' + type + '/' + nodeid;
        } else if (target == 'partner') {
            if(type == 'filter') {
				var currentNode = $('#partners-slider').attr('nodeid');
				var param = '';
				ajax_url = '/ajax/partner/' + target + '/' + type + '/' + currentNode + '/';
                $.each(nodeid, function(key,val) {
                    param = param + val.value + '/';
                });
                ajax_url = ajax_url + param;
            }
			else if(type == 'detail') {
				ajax_url = '/ajax/partner/' + target + '/' + type + '/' + nodeid + '/';
			}
        } else if (target == 'events') {
            var param = '';
            $.each(type, function(key,val) {
                if (val.value) {
                    param = param + $(this).parent().attr('name') + '/' + val.value + '/';
                }
            });
            ajax_url = '/ajax/events/' + nodeid + '/' + param;
        } else if (target == 'overlay') {
            ajax_url = '/ajax/overlay/' + nodeid +'/' + container.overlaysource + '/overlayload/no';
        }
        ajax_url = '/' + $('#language-select').attr('lang') + ajax_url;
        $.ajax({
            type: "GET",
            url: ajax_url,
            async: ajax_async,
            dataType: ajax_dataType,
            beforeSend: function() {
                if (target == 'case' || target == 'crm' || target == 'events') {
					if(type != 'extendBreadcrumb') {
						$('#loading-layer').show();
					}
                } else if(target == 'partner' && type == 'filter') {
                    $('#loading-layer1').show();
                } else if(target == 'partner' && type == 'detail') {
                    $('#loading-layer1').show();
                }
            },
            success: function(msg) {
                var ezu = new ezp_update();
                if(target == 'case') {
                    
                } else if(target == 'partner') {
                    if(type == 'filter') {
                        $('#partners-slider').css('display','none').html(msg).fadeIn(3000);
                        ezu.initPartner(true);
                        $('#loading-layer1').hide();
                    } else if(type == 'detail') {
                        $('#full-partner-detail-slider').css('display','none').html(msg).fadeIn(3000);
                        ezu.initDownloadArea();
                        $('#loading-layer1').hide();

                    }
                } else if(target == 'crm') {
                    
                } else if(target == 'events') {
                    $('#events-slider').html(msg);
                  
                   slider = $("#events-slider .items-holder").scrollable({
                        api: true,
                        speed: 700,
                        size: 3,
                        hoverClass: 'active',
                        onSeek: function() {
                            container.setPageSlider(this);
                        }
                     });
                     if(slider)
                        container.setPageSlider(slider);
                    
					$('#loading-layer').hide();
                } else if(target == 'overlay') {
                    window.location = 'http://'+jQuery.url.attr("host") + '/' + msg;
                }
                $("#datastore").data("case", {slider: false});
                $("#datastore").data("crm", {slider: false});
            }
        });
    },
    this.changeNavigation = function(element, id_text) {
        $('.case-box-bottom a').removeClass('url-1-active').removeClass('url-2-active').removeClass('url-3-active');
        $('.case-box-bottom li').removeClass('first-active').removeClass('list-active');
        if(id_text == 'case-why') {
            $(element).addClass('url-1-active');
            $(element).parent().addClass('first-active');
        } else if(id_text == 'case-modul') {
            $(element).addClass('url-3-active');
            $(element).parent().addClass('list-active');
        } else if(id_text == 'case-keybenefits') {
            $(element).addClass('url-2-active');
            $(element).parent().addClass('list-active');
        }
    },
// disable Navgation in CRM
    this.disableTabNavigation = function() {
        tabcounter = 0;

        $(".case-detail-navigation a[rel='history']").each(function() {
            if(tabcounter != 0) {
                if(lastTabNodeId != $(this).attr('nodeid')) {
                    $(this).hide();
                    $(this).unbind('class');
                } else {
                    $(this).show();
                    $(this).attr('class','active');
                    $('#crm-back-to-overview').show().click(function() {
                        $('.case-detail-navigation a[rel=history]:eq(0)').click();
                    });
                }
            }
            tabcounter++;
        });
    },
// init all VerticalScroller @dho
    this.initVerticalScroller = function(type) {
        if(type == 'crm') {
            $("#infinite_crm").scrollable({
                speed: 700,
                size: 4,
                activeClass: 'crm-scroller-set',
                hoverClass: 'crm-scroller-hover'
            });
            $('.crm-scroller').click(function() {
                lastTabNodeId = 0;
                container.getData('crm','crm_modules',$(this).attr('nodeid'));
                return false;
            });
        } else if(type == 'case') {
            $("#infinite").scrollable({
                speed: 700,
                size: 8,
                hoverClass: 'case-scroller-hover',
                activeClass: 'case-scroller-set'
            });
        }

    },

    this.setPageSlider = function(e) {
        var max = (e.getPageIndex() + 1) * e.getPageAmount();
        var first = 0;
        var last = 0;
        $.each(e.getVisibleItems(), function(key,itemX) {
            if(!first)
                first = $(itemX).attr('slideritem');
            last = $(itemX).attr('slideritem');
            
        });
        
        $('#slider-info-pageresult').html(first + '-' + last + ' ');
        $('#slider-info-result').html(e.getSize());
    },
    
// init Jobs @dho
    this.initJob = function() {
        $("#job-list").hide();
		$("#job-slider-block").show();
        
         var slider = $("#job-slider .items-holder").scrollable({
            api: true,
            speed: 700,
            size: 3,
            hoverClass: 'active',
            onSeek: function() {
                container.setPageSlider(this);
            }
         });
         if(slider)
            container.setPageSlider(slider);

         $("#job-slider .gal-frame").click(function() {
			if ($(this).find('a:first').attr('href')) {
				window.location = $(this).find('a:first').attr('href');
                return false;
			}
		}).hover(function() {$(this).css('cursor','pointer');});
    },
// init Events @dho/@ibr
    this.initEvents = function() {
        $("#events-list").hide();
		$("#events-slider-block").show();

        
        slider = $("#events-slider .items-holder").scrollable({
            api: true,
            speed: 700,
            size: 3,
            hoverClass: 'active',
            onSeek: function() {
                container.setPageSlider(this);
            }
         });
         if(slider)
            container.setPageSlider(slider);
        
        $(".event-filter").change(function() {
            container.getData('events', $('.event-filter option:selected'), $('#events-slider').attr('nodeid'));
			container.reloadEvents();
        });
        
        
		container.reloadEvents();
        
        $('#timezone').timezoneComboBox( {refreshTime: 100000} );
        var Event2Outlook = $('#addtocalendar').attr('href');
        $('#addtocalendar').click(function() {
            $(this).attr('href', Event2Outlook + '/'+$('#timezonePrivate').val());
            return true;
        });
        
    },
	this.reloadEvents = function() {
		$("#events-slider .gal-frame").click(function() {
			if ($(this).find('a:first').attr('href')) {
				window.location = $(this).find('a:first').attr('href');
				return false;
			}
		}).hover(function() {
			if ($(this).find('a:first').attr('href')) {
				$(this).css('cursor','pointer');
			}
		});
    },
    this.overlayload = function() {
        $(".overlay-link, .autoplay-overlay-link, .video").attr({'rel':'#overlay','href': function() {
            var source = $(this).attr('href');
			var replacePart = new RegExp('http://'+window.location.hostname,'g');
			source = source.replace(replacePart, '');
            source = source.replace(/\//g, '___');
            return '/'+$('#language-select').attr('lang') + '/ajax/overlay/' + source;
            }});
        $(".overlay-link, .autoplay-overlay-link, .video").click(function() {
            $("#overlay").addClass('content-overlay');
        });

        $(".image-overlay-link").attr({
            'rel'       :   '#overlay',
            'href': function() {
                                var source = $(this).attr('href');
                                var replacePart = new RegExp('http://'+window.location.hostname,'g');
                                source = source.replace(replacePart, '');
                                source = source.replace(/\//g, '___');
                                return '/'+$('#language-select').attr('lang') + '/ajax/overlay/' + source + '/loadimage/';
                                }
            }).click(function() {
                $("#overlay").addClass('content-overlay');
            });

		this.overlay_api = $("a[rel=#overlay]").overlay({
			expose: '#fbfbfb',
			effect: 'apple',
			onBeforeLoad: function() {
				var wrap = this.getContent().find(".contentWrap");

				if(this.getTrigger().attr("id") == 'getcontact') {
					wrap.load('/' + $('#language-select').attr('lang') + this.getTrigger().attr("href") + '/' + $('#node-id').html());
				} else {
					wrap.load(this.getTrigger().attr("href") + '/'+$('#node-id').html());
				}
			},
			onLoad: function() {
				container.initGetContact();
			},
			onClose: function() {
				if ($("#overlay").hasClass('content-overlay')) {
					$("#overlay").removeClass('content-overlay');
				}
				var wrap = this.getContent().find(".contentWrap");
				wrap.html('');
			}
		});
		
		// set cookie to prevent multiple autoload?
		$("a[rel=#overlay].autoplay-overlay-link").click(function () {
			$.cookie(window.location.pathname, true);
		});
		
		// autoplay overlay?
		if(!$.cookie(window.location.pathname)) {
			$("a[rel=#overlay].autoplay-overlay-link").trigger('click');
		}

        if(jQuery.url.param("articlenode")) {
            var source = jQuery.url.attr("directory");
            this.overlaysource = source.replace(/\//g, '___');
            this.getData('overlay','',jQuery.url.param("articlenode"));
        } else if(jQuery.url.param("overlaypath")) {
            $("a[rel=#overlay]").each(function() {
                if($(this).attr('href') == '/ajax/overlay/' + jQuery.url.param("overlaypath")) {
                    $(this).click();
                }
            });
        }



    },
    this.initDownloadArea = function() {
        $('div.insights-box > ul').accordion({
            active: ".selected",
            autoHeight: false,
            header: ".opener",
            collapsible: true,
            event: "click"
        });
        $('div.insights-box ul ul').accordion({
            active: ".selected",
            autoHeight: false,
            header: ".subopener",
            collapsible: true,
            event: "click"
        }).bind('accordionchange', function(event, ui) {
            reset_id = $(this).attr('id');
            if($('#'+reset_id + ' .table1').length && $('#'+reset_id + ' .table2').length) {
                if(this.active_downloadtab == 'table2') {
                    $('#'+reset_id + ' .table1').hide();
                    $('#'+reset_id + ' .table2').show();
                } else {
                    $('#'+reset_id + ' .table2').hide();
                    $('#'+reset_id + ' .table1').show();
                }
                $('div.insights-box li.first').click(function() {
                    $(this).addClass();
                    $('#'+reset_id + ' .table2').hide();
                    $('#'+reset_id + ' .table1').show();
                    $('div.insights-box li.last a').removeClass('active');
                    $('div.insights-box li.first a').addClass('active');
                    this.active_downloadtab = 'table1';
                    return false;
                });
                $('div.insights-box li.last').click(function() {
                    $('#'+reset_id + ' .table1').hide();
                    $('#'+reset_id + ' .table2').show();
                    $('div.insights-box li.first a').removeClass('active');
                    $('div.insights-box li.last a').addClass('active');
                    this.active_downloadtab = 'table2';
                    return false;
                });
            }

        });
    },

	this.initCaseBreadcrumbs = function() {
        $('#case-header-branche-2').click(function() {
            $('#full-case-detail').hide();
            $('#full-case-detail-slider').hide();
			$('.case-box-bottom ul').hide();
			if(jQuery.browser['msie']) {
                $("#case-flash").removeClass('disableonIE');
				document.getElementById('case-object-container').showBranches();
			} else {
				$("#case-flash").css({'visibility':'visible','height':'400px'});
				$('#case-object-container')[0].showBranches();

			}
			return false;
        });

        $('#case-header-branche-3').click(function() {
            $('#full-case-detail').hide();
            $('#full-case-detail-slider').hide();
			if(jQuery.browser['msie']) {
                $("#case-flash").removeClass('disableonIE');
			} else {
				$("#case-flash").css({'visibility':'visible','height':'400px'});
			}
			return false;
        });
	},
	this.initForms = function() {
        $('form').submit(function() {
            $('#forms .submit').append($('#formloader').html());
            $('#forms input[type=submit]').hide();
        });
        if($('#questionary-form').length == 1) {
            
        } else {
            if($('.microland').length > 0) {
                $("#forms input[title!=''],#forms select[title!=''],#forms textarea[title!='']").tooltip({
                    position: "top center",
//                    offset: [0, 0],
                    effect: "fade",
                    opacity: 1,
                    tip: '.microlandtooltip',
                    onShow : function() {
                        var microlandtip = this.getTip();
                        var txt = $(microlandtip).html();
                        if($(microlandtip).children('.input-arrow').length == 0) 
                            $(microlandtip).html('<div class="microland-input-arrow" >'+txt+'</div><img src="/design/em_plain_site/images/microsite/input-bg.png" />');
                        
                        var _top = $(microlandtip).css('top');
                        _top = _top.replace('px','');
                        $(microlandtip).css('top',(_top - 9)+'px');
                        
                    }
                }).focus(function() {
                    if($(this).parent().parent().hasClass('error')) {
                        $('.tooltip').addClass('error');
                    } else {
                        $('.tooltip').removeClass('error');
                    };
                }).hover(function() {
                    if($(this).parent().parent().hasClass('error')) {
                        $('.tooltip').addClass('error');
                    } else {
                        $('.tooltip').removeClass('error');
                    };
                }); 
            } else {
              var formTooltip = $("#forms input[title!=''], #forms select[title!=''], #forms textarea[title!='']")
              $("#forms .survey-form input[title!=''][type!='radio'][type!='checkbox']",formTooltip).tooltip({
                    position: "center right",
                    offset: [3, 10],
                    effect: "fade",
                    opacity: 1,
                    tip: '.tooltip'
                }).focus(function() {
                    if($(this).parent().parent().hasClass('error')) {
                        $('.tooltip').addClass('error');
                    } else {
                        $('.tooltip').removeClass('error');
                    };
                }).hover(function() {
                    if($(this).parent().parent().hasClass('error')) {
                        $('.tooltip').addClass('error');
                    } else {
                        $('.tooltip').removeClass('error');
                    };
                });  
            }
            
        }
        

       // $("#personal_data-phone").mask("+(99)-(999)-99999999999");

    },
// route to LANGCode
    this.ipRouting = function() {
        
        
       // if(GetCookie('CIPRouting') == 'set') {
          //  $('#iprouting').html('NOTHING');
       // }
        
        if(($('#iprouting').html() != 'NOTHING') && ($('#language-select').attr('lang') != $('#iprouting').html())) {
            $('#lang-list li a').each(function() {
                if($(this).attr('lang') == $('#iprouting').html()) {
                    var query = '';
                    if(jQuery.url.attr("query") != null) {
                        query = '/?' + jQuery.url.attr("query");
                    }
                    if(jQuery.url.segment(0) != 'campaign' && jQuery.url.segment(1) != 'campaign' && jQuery.url.segment(1) != 'revolution') {
                        //if($(this).attr('href') != ('/' + $(this).attr('lang')) || GetCookie('iprouting') != 'set') {
                        if($(this).attr('href') != ('/' + $(this).attr('lang'))) {
                            window.location = $(this).attr('href') + query;        
                        }
                    }
                }
            });
        }

       // if(GetCookie('iprouting') != 'set') {
       //     var expire = new Date();
       //     var expireTime = expire.getTime() + (5000 * 24 * 3600 * 1000);
       //     expire.setTime(expireTime);
       //     document.cookie = "CIPRouting=set; Path=/; expires=" + expire.toGMTString();
       // }
    },
    this.initGetContact = function() {
        $('.getcontact-item').each(function() {
            var getcontacthref = $(this).attr('getcontactlink');
            if(getcontacthref) {
                $(this).click(function() {
                    window.location = getcontacthref;
                });
            }
        });
        $('#startchat').live('click', function() {
            $('#startchat a').click();
        });

    },
    this.initRevolution = function() {
        //var maxHeight = $('#barometer').height();
        var maxHeight = 415;
            $(window).scroll(function(){
                if( parseInt($('.barometer').css('marginTop')) <= maxHeight || $('.barometer').css('marginTop') == '0px' || $('.barometer').css('marginTop') == 'auto' ){
                    $('.barometer').animate({
                        'marginTop': $(this).scrollTop()
                    }, {queue: false});
                }
                if($(this).scrollTop() < parseInt($('.barometer').css('marginTop'))){
                    $('.barometer').animate({
                        'marginTop': $(this).scrollTop()
                    }, {queue: false});
                }
            });
        $('input[type=radio]').click(function() {
            var radiofield = $(this).attr('name');
            radiofield = radiofield.replace('questions[','');
            radiofield = radiofield.replace('question','');
            radiofield = radiofield.replace(']','');
            $.ajax({
                type: "GET",
                async: true,
                dataType: 'json',
                url: "/" + $('#language-select').attr('lang') + "/revolution/campaign/getpoints/" + $('#uid').attr('value') + '/' + radiofield + '/' +$(this).attr('value'),
                success: function(barometer){
                    $(".barometer-empty").animate({ 
                        height: (210 - barometer.height)+ "px"
                    }, 1500 );
                    
                    i=i+1;
                }
            });
            
        });
        
        $('.wallpaper1680').click(function() {
            var url = 'http://' + jQuery.url.attr("host") + '/revolution/campaign/download/'+$('#uhash').html()+'/1680';
            window.open(url,"window","width=300,height=400");
            return false;
        });
        
        $('.wallpaper1280').click(function() {
            var url = 'http://' + jQuery.url.attr("host") + '/revolution/campaign/download/'+$('#uhash').text()+'/1280';
            window.open(url,"window","width=300,height=400,resizable=yes");
            return false;
        });
        
        if($('#landingpage').length == 1) {
            $('.barometer-box').hide();
        }
        
    //barometer-red
    },
    
    //Social media
    this.initSocialMedia = function() {
        $('.iconbar li').each(function(i) {
            $(this).hover(function() {
                el = this;
                $('span.s1', this).stop().animate({'left' : '-20px'}, {queue:false,duration:500});
                $('span.s2', this).stop().animate({'top' : '-20px'}, {queue:false,duration:500});
                $('span.s3', this).stop().animate({'right' : '-20px'}, {queue:false,duration:500});
                $('span.s4', this).stop().animate(
                    {'bottom' : '-20px'},
                    {
                        queue       :   false,
                        duration    :   500,
                        complete: function() {
                           $(el).parent().parent().removeClass('sm-icon').addClass('sm-icon-set').queue();
                           $(el).parent().after('<div class="sm-icon-description">'+$(el).children('a').attr('stitle')+' <span class="sm-icon-application">'+$(el).children('a').children('img').attr('stitle')+'</span></div>');
                           $('.sm-icon-description').show();
                            $('.sm-icon-description').mouseout(function() {
                                $(this).remove();
                            });
                        }
                    }
                );
            }, function() {
                $(this).parent().parent().removeClass('sm-icon-set').addClass('sm-icon');
                $('.sm-icon-description').stop();
                $('.sm-icon-description').remove();    
                $('span.s1', this).animate({'left' : '0'}, {queue:false,duration:500});
                $('span.s2', this).animate({'top' : '-0'}, {queue:false,duration:500});
                $('span.s3', this).animate({'right' : '-0'}, {queue:false,duration:500});
                $('span.s4', this).animate({'bottom' : '0'}, {queue:false,duration:500});
                //if($('.iconbar span:animated') || $('.sm-icon-description:animated')) {
                  //  _log('drinnen');
                    
                //} 
            });
        });
    },
    this.createPlayButton = function(e,type) {
        var width = 0;
        if(type == 'download') {
            width = Math.round($('img',e).attr('width') / 2) - 10;
        } else {
            width = Math.round($('img',e).attr('width') / 2) - 32;
        }
        
        var height = Math.round($('img',e).attr('height') / 2) + 32;
        //position:relative;margin:auto;width:64px
        
        var playerId = Math.floor(Math.random()*99999);
        $(e).append('<div style="position:relative"><div style="position:absolute;top:-'+height+'px;left:'+width+'px;" class="'+type+'-player" id="'+playerId+'"></div></div>');
        $(e).hover(function() {
            $('#'+playerId).attr('class',type + '-player-hover');
        }, function() {
            $('#'+playerId).attr('class',type + '-player');
        });
    },
// init Website @dho
    this.initSite = function() {
        //this.ipRouting();
        this.overlayload();
        this.initRevolution();
        $('#no-js-case').hide();

        this.loadjScrollPane();
        this.initInfoboxes();
        this.initFrexibleMenu();
        this.loadTabNavigationController('','');
        this.initPartner(false);
        this.initEvents();
        this.initJob();
        this.initDownloadArea();
        this.initForms();
        this.initSocialMedia();

        if ($.browser.msie) {
            $("a.arrow, a.info").css({"background": "none"});
            //$("a.arrow .arrow-content").css({"float": "none"});
            
            $("a.arrow, a.info").append('  <img class="arrow-content" src="/design/em_plain_site/images/bullet04.gif" alt="" />');
            $(".bottom-box .col a img").css("float", "none");
        }


        // if IE 7 no history (jump )
        if(jQuery.browser['msie'] &&  jQuery.browser['version'] >= 7 && jQuery.browser['version'] < 8) {
            $("ul.tabs").tabs("div.panes > div.panecontent", {effect: 'fade'});    
        } else {
            $("ul.tabs").tabs("div.panes > div.panecontent", {effect: 'fade'}).history();
        }
        
        $(".panel-content-wrapper .tab-content-controller").click(function() {
            $(this).parent('.panel-content-wrapper').children('.content-bottom').slideToggle().show();
            
        });

       // $('#startpage-non-flash').attr('style','display:none');

        $('ul.accordion a').hover(function() {
            $(this).addClass('ui-state-hover');
        },function() {
            $(this).removeClass('ui-state-hover');
        });

        $('ul.accordion2').accordion({
            autoHeight: false,
            header: ".opener",
            collapsible: true,
            fillSpace: true,
            event: "click"
        });

        if($('#startpage-news-events').length == 1) {
            var tid;
            $('#startpage-news-events').hover(
                                                function() {
                                                    clearInterval(tid);
                                                },
                                                function() {
                                                    tid = container.getNewsEvents();
                                                }
                                            );
            tid = container.getNewsEvents();
        }
        $('div.nav-item:has(a)').click(function() {
            window.location = $(this).find('a:first').attr('href');
        });

        $('div.nav-item').hover(function() {
            $(this).css({'cursor' : 'pointer'});
        });

        $('#SearchField').focus(function(){
            $(this).attr('value', '');
        }).autocomplete('/' + $('#language-select').attr('lang') + '/autocomplete/content', {
            minChars : 3,
            width: 160,
            max : 5
        });

        // KBP Call
        $('#kbpcall-start').click(function() {
            redirektToLink();
        });

        var slider = $("#content-slider").scrollable({
            api: true,
            speed: 700,
            size: 3,
            hoverClass: 'content-scroller-hover',
            activeClass: 'content-scroller-set',
            onSeek: function() {
                container.setPageSlider(this);
            }
         });



         if(slider)
            container.setPageSlider(slider);

         $('.content-scroller').each(function() {
             if($(this).attr('nodeid') == $(this).attr('parent_nodeid')) {
                //_log($(this).attr('index'));
                slider.click($(this).attr('index'));
             }
         });
         
        var case_slider = $("#case-item-slider").scrollable({
            api:true,
            vertical:true,
            size: 3,
            hoverClass: 'case-scroller-hover',
            activeClass: 'case-scroller-set',
            onSeek: function() {
                container.setPageSlider(this);
            }
         });
         
        if(case_slider)
            container.setPageSlider(case_slider);

        $('#case-item-slider .case-scroller').each(function() {
             if($(this).attr('nodeid') == $(this).attr('parent_nodeid')) {
                case_slider.click($(this).attr('index'));
             }
         });

        $('#content-slider .content-scroller').click(function() {
            window.location = $('a',this).attr('href');
        });
        if($('#play-button').length > 0) {
            // hover only for video player
            $('.overlay-link').each(function() {
                if($('img',this).length > 0) {
                    container.createPlayButton(this,'video');
                }
            });
			
            // hover only for autoplay video player
            $('.autoplay-overlay-link').each(function() {
                if($('img',this).length > 0) {
                    container.createPlayButton(this,'video');
                }
            });			

            // hover only for single image and gallery
            $('.image-overlay-link').each(function() {
                if($('img',this).length > 0) {
                    container.createPlayButton(this,'gallery');
                }
            });

            // downloadcorner
            $('.download-overlay-link').each(function() {
                if($('img',this).length > 0) {
                    container.createPlayButton(this,'download');
                }
            });

        }
        if($('.sitemap-nav').length > 0) {
            $('.sitemap-nav').toggle(
                function() {
                    $(this).parent().parent().parent().parent().next().fadeIn().css({'border' : '1px solid #c6c7cc', 'padding-top' : '5px', 'padding-bottom' : '5px'});
                    var _sitemap = $(this).attr('src');
                    $(this).attr('src',_sitemap.replace('plus','minus'));
                },
                function() {
                    $(this).parent().parent().parent().parent().next().fadeOut();
                    var _sitemap = $(this).attr('src');
                    $(this).attr('src',_sitemap.replace('minus','plus'));
                }
            );
        }
        $(".cs-overview li[title!='']").each(function()
           {
              $(this).qtip(
              {
                 content: set_tooltipCase(this),
                 position: {
                    corner: {
                       target: 'topMiddle', // Position the tooltip above the link
                       tooltip: 'bottomMiddle'
                    },
                    adjust: {
                       screen: true // Keep the tooltip on-screen at all times
                    }
                 },
                 style: {
                    width: get_TooltipWidthCase(),
                    background: 'none',
                    border:0
                },
                effect: {
                    type: 'slide'
                }
              })
           });
       $(".vc-overview li[title!='']").each(function()
           {
              $(this).qtip(
              {
                 content: set_tooltipVCDC(this),
                 position: {
                    corner: {
                       target: 'topMiddle', // Position the tooltip above the link
                       tooltip: 'bottomMiddle'
                    },
                    adjust: {
                       screen: true // Keep the tooltip on-screen at all times
                    }
                 },
                 style: {
                    width: get_TooltipWidth(),
                    background: 'none',
                    border:0
                }
              })
           });

        // GA tracking for Download Corner
        $('ul.dc-overview li a.download-overlay-link').click(function() {
            pageTracker._trackEvent('Download', 'DownloadCorner', $(this).attr('href'));
            return true;
        });

        // Rest of GA Tracking of Documents
        $('a[href*="content/download"]:not(a.download-overlay-link)').click(function() {
            pageTracker._trackEvent('Download', 'Website', $(this).attr('href'));
            return true;
        });
        
        // from share it? start video overlay
        var share_source = jQuery.url.attr("relative");
        if(share_source.search(/\?/i) > 0) {
            if(jQuery.url.param("share_id")) {
                $('.vc-overview a[node='+jQuery.url.param("share_id")+']').click();
            }
        }
		
		// microsite-form-hack (dmu 27.07.2011)
		/*$('#personal_data-hiddeninput_testheadline').each(function()
			{
				//$(this).hide();
				$(this).parent().parent().css({'height':'40px'});
				$(this).parent().parent().find('label').css({'position':'absolute', 'width':'300px', 'font-weight':'bold'});
			});*/
        
    }
}
function set_tooltipVCDC(e) {
    if($.browser.msie) {
        return '<div class="tooltip-border"><img src="/design/em_plain_site/images/vc/tooltip-t-ie.jpg" /><div class="cs-tooltip-bg vc-tooltip-bg">'+$('#cs-quote-tooltip-'+$(e).attr('nodeid')).html()+'</div><img src="/design/em_plain_site/images/' + $(e).attr('displayType') + '/tooltip-b-ie.jpg" />';
    } else {
        return '<img src="/design/em_plain_site/images/vc/tooltip-t.png" /><div class="cs-tooltip-bg vc-tooltip-bg">'+$('#cs-quote-tooltip-'+$(e).attr('nodeid')).html()+'</div><img src="/design/em_plain_site/images/' + $(e).attr('displayType') + '/tooltip-b.png" />';
    }
}
function set_tooltipCase(e) {
    if($.browser.msie) {
        return '<img src="/design/em_plain_site/images/case_study/tooltip-top-ie.jpg" /><div class="cs-tooltip-bg cs-tooltip-ie">'+$('#cs-quote-tooltip-'+$(e).attr('nodeid')).html()+'</div><img src="/design/em_plain_site/images/case_study/tooltip-bottom-ie.jpg" />';
    } else {
        return '<img src="/design/em_plain_site/images/case_study/tooltip-top.png" /><div class="cs-tooltip-bg">'+$('#cs-quote-tooltip-'+$(e).attr('nodeid')).html()+'</div><img src="/design/em_plain_site/images/case_study/tooltip-bottom.png" />';
    }
}
function get_TooltipWidth() {
    if($.browser.msie) {
        return 282;
    } else {
        return 450;
    }
}
function get_TooltipWidthCase() {
    if($.browser.msie) {
        return 425;
    } else {
        return 450;
    }
}
function initSiteAccess() {
    var source = jQuery.url.attr("relative");
    if(source.search(/#/i) > 0) {
        source = source.replace(/^.*#\/.*?\/.*?\//, '/');
        source = source.replace(/#/, '');
        source = source.replace(/\//g, '#');
        ezu.getData('case','loadevent', source);
    }
}

function rewriteFlashHandler(rewrite_nodeid) {
    container.getData('case','rewrite_url',rewrite_nodeid);
	$('.case-box-bottom ul').show();
    $('.case-box-bottom a:first').addClass('url-1-active');
    $('.case-box-bottom li:first').addClass('first-active');
}

function caseFlashHandler(nodeid, rewrite_nodeid) {
	container.getData('case','rewrite_url',rewrite_nodeid);
	if(jQuery.browser['msie']) {
		$("#case-flash").addClass('disableonIE');
	} else {
		$("#case-flash").css({'visibility':'hidden', 'height':'1px'});
	}
    $('.case-box-container').show();
	$('#full-case-detail').show();
	container.caseFlashHandler(nodeid);
    $('.case-box-bottom a:first').addClass('url-1-active');
    $('.case-box-bottom li:first').addClass('first-active');
}

function extendBreadcrumb(branchid, subbranchid) {
	container.subbranchid = subbranchid;
	container.getData('case', 'extendBreadcrumb', branchid);
}

function GetCookie (name) { 
    var arg = name + "="; 
    var alen = arg.length; 
    var clen = document.cookie.length; 
    var i = 0; 
    while (i < clen) { 
        var j = i + alen; 
        if (document.cookie.substring(i, j) == arg) 
        return getCookieVal (j); 
        i = document.cookie.indexOf(" ", i) + 1; 
        if (i == 0) break; 
    } 
    return null;
}

function getCookieVal (offset) { 
    var endstr = document.cookie.indexOf (";", offset); 
    if (endstr == -1) 
    endstr = document.cookie.length; 
    return unescape(document.cookie.substring(offset, endstr));
}
function _log(msg) {
    if (window.console && window.console.log)
        window.console.log(msg);
}

var addthis_config;
function setAddThis() {
    
    var addthis_config = {
        ui_language: $('#language-select').attr('lang')
    }
    _log(addthis_config);
}

/*  ====  KBP CALL  ====  */


function PAufbau(strParameter, nAnzahl) {
    var i = 0;
    var j = 0;
    var strVector;
    var strVector2;
    var strParameterNeu = strParameter;

    for( i = 0; i < nAnzahl; i++ ) {
        strVector = "";
        strVector2 = "";
        for( j = 0; j < strParameterNeu.length; j++ )
        {
            if( j%2 == 0 )
                strVector = strVector + strParameterNeu.substr(j,1);
            else
                strVector2 = strParameterNeu.substr(j,1) + strVector2;
        }
        strParameterNeu = strVector + strVector2;
    }
    return strParameterNeu;
}

function PZusammestellen(strKundennummer, strBerater) {
    var strKdNrCode = "";
    var strTSCode = "";
    var strBeraterCode = "";
    var strParameter = "";
    var strTimeStamp = "";

    var j = 0;

    var Jetzt = new Date();
    var nAktSek = Jetzt.getSeconds();

    strTimeStamp = (( Jetzt.getYear()%100 < 10) ? "0" : "") + Jetzt.getYear()%100;
    strTimeStamp = strTimeStamp + (( (Jetzt.getMonth()+1) < 10) ? "0" : "") + (Jetzt.getMonth()+1);
    strTimeStamp = strTimeStamp + (( Jetzt.getDate() < 10) ? "0" : "") + Jetzt.getDate();

    strTimeStamp = strTimeStamp + (( Jetzt.getHours() < 10) ? "0" : "") + Jetzt.getHours();
    strTimeStamp = strTimeStamp + (( Jetzt.getMinutes() < 10) ? "0" : "") + Jetzt.getMinutes();
    strTimeStamp = strTimeStamp + (( nAktSek < 10) ? "0" : "") + nAktSek;

    nAktSek = nAktSek%10;
    if( nAktSek == 0 )
        nAktSek = nAktSek + 1;

    for( j = strKundennummer.length; j < 10; j++ ) {
        strKundennummer = "0" + strKundennummer;
    }

    strTSCode = PAufbau(strTimeStamp, nAktSek);
    strKdNrCode = PAufbau(strKundennummer, nAktSek);
    strBeraterCode = PAufbau(strBerater, nAktSek);

    if( strKdNrCode.length < 10 )
        strParameter = "0" + strKdNrCode.length;
    else
        strParameter = strKdNrCode.length;

    if( strBeraterCode.length < 10 )
        strParameter = strParameter + "0" + strBeraterCode.length;
    else
        strParameter = strParameter + strBeraterCode.length;

    for( j = 0; j < strKdNrCode.length || j < strBeraterCode.length || j < strTSCode.length; j++ ) {
        if( j < strKdNrCode.length )
            strParameter = strParameter + strKdNrCode.substr(j,1);
        if( j < strBeraterCode.length )
            strParameter = strParameter + strBeraterCode.substr(j,1);
        if( j < strTSCode.length )
            strParameter = strParameter + strTSCode.substr(j,1);
    }

    strParameter = nAktSek + PAufbau(strParameter, nAktSek);

    return strParameter;
}

function redirektToLink() {
    var MODUL = $('#modul').attr('value');
    var KUNDE = $('#customer').attr('value');

    var strBerater = "KBP";
    var strParameter = "";
    var strServerUrl = "https://www.orgaplan-software.de/";
    var strMandant = ""
    var strBaseParameter = "&format=normal&singlelogon=benutzer&aufrufer=kbp&clienttyp=html&server=https://www.orgaplan-software.de&kms=";
    var strZiel = "";
 
    if ( MODUL == 123 || MODUL == 124 || MODUL == 106) {
       strMandant = "&mandant=" + "89998";
       strZiel = "https://www.orgaplan-software.de/" + "webframeKbp/start-login.jsf?aktion=startkms&fbuid=" + MODUL;
    } else  {
       strMandant = "&mandant=" + "89998";
       strZiel = "https://www.orgaplan-software.de/" + "kmsWebapp/kms?aktion=startkms&fbuid=" + MODUL;
    }
 
    strParameter = PZusammestellen(KUNDE, strBerater);
    strZiel = strZiel + strMandant + strBaseParameter + strParameter;
 
    window.open(strZiel,"", "width=1024,height=768,left=0,top=0, scrollbars=yes");
}









