/**
 * Config Area
 */

var config = {
	animatespeed:		200,	// Fading Speed
	stageFadingSpeed:	1000,		// Fading Speed
	stageFadingTime:	5000		// Change Time
}

var $j = jQuery.noConflict();
jQuery().ready(function(){ 




$j('.ie #right > .inside > .block:last-child, .ie #right > .inside > .mod_article > .block:last-child').addClass('last');






$j('.ie a[rel=lightbox] img:not(#right img)').css({
	'border': '1px solid #BEBEBE',
	'padding':'1px'
	
})




jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};






jQuery.fn.exists = function(){return jQuery(this).length>0;};

// Scroll to Top     
jQuery.fn.scrollToTop=function(){
	var ToTop=jQuery(this); // Variable initialisieren      
	jQuery(this).removeAttr("href");
	
		jQuery(window).scroll(function(){ // Windows Scroll-Event         
		if(jQuery(window).scrollTop()=="0"){ 
			jQuery(ToTop).fadeOut("slow") // ToTop-Link ausblenden wenn die Scroll-Position 0 ist 
		} else{ 
			jQuery(ToTop).fadeIn("slow") // ToTop-Link einblenden wenn die Scroll-Position nicht 0 ist
		}
	});                
	      
	jQuery(this).click(function(){ // Klick des ToTop-Links
		jQuery("html, body").animate({scrollTop:0}, {duration:'slow', easing: 'easeOutQuad'});          
	})      
}
	
jQuery("#toTop").scrollToTop(); // Zuweisen von scrollToTop    

$j('#fontResize').each(function(){

	//alert($j.cookie('compart-com-font-size'));
	
	$j(this).find('#small, #middle, #big').click(function(){
		
		currentSize = $j(this).attr('id');
		
		$j('body').removeClass('small middle big')
		$j('body').addClass(currentSize);
		
		$j.cookie('compart-com-font-size', currentSize);
		
		
		$j('.ce_accordion .accordion').each(function(){
			if($j(this).height() > 0){
				$j(this).css('height','auto');
			}
		})
		
		return false;
	});
})

	
/*
 * Sliding on Frontpage
 */
					
changeSlideTeaser = function($jitems, ItemIndex ,newActiveIndex, duration){	

	
	if($jitems.filter(':eq('+ItemIndex+')').css('opacity')== 0 || $jitems.filter(':eq('+ItemIndex+')').css('opacity')== 1 ){
	
		$jitems.stop();
		$jitems.filter(':eq('+newActiveIndex+')').fadeIn(duration);
		$jitems.not(':eq('+newActiveIndex+')').fadeOut(duration);				
	}					
}

$j.fn.makeSlider = function(singleSlideItem, duration){
	if($j(this).exists()){$j(this).each(function(){	

		singleSlideItem = singleSlideItem || '.item';				
		$jsingleSlideItems = $j(this).find(singleSlideItem);
				
		//default Fade Duration
		duration = duration || 300;
										
		$jsingleSlideItems.hide();
		$jsingleSlideItems.filter(':first').show();			
				
		x = 1;		
		(function fadeTimer(){
		
			itemIndex = $jsingleSlideItems.index($jsingleSlideItems.filter(':visible'));			
			newItemIndex = (itemIndex+1)>=$jsingleSlideItems.length?0:(itemIndex+1);		
			changeSlideTeaser($jsingleSlideItems, itemIndex, newItemIndex, config.stageFadingSpeed);
			setTimeout(fadeTimer,config.stageFadingTime);					
		})()			
	})}
}



$j('#Banner').makeSlider('#banner > .ce_text', config.stageFadingSpeed);
		
if(jQuery.browser.msie && jQuery.browser.version < 7){} ;

$j('.nav_top').scrollToTop();

//$j('#comparting-2010-registration-form').each(function(){
/*
$j('.ce_accordion:first').closest('.mod_article').add('#comparting-2010-registration-form').each(function(){

	$j(this).find('fieldset:not(:first, :last)').each(function(){
	
	$j(this).addClass('active-slider');
	$jfieldsetContent = $j(this).children();

	$jfieldsetContent.filter(':not(legend)').wrapAll('<div class="slide-cnt"><div class="slide-cnt-inner"></div></div>');
	
	$jfieldsetContent.filter('legend').addClass('toggleLabel').click(function(){
		$j(this).children('span').toggleClass('active');
		$j(this).next().slideToggle(400);
	}).wrapInner('<span />');
		
	})
	
	$j(this).find('.toggleLabel:first span').addClass('active');	
	$j(this).find('.slide-cnt:not(:first)').slideToggle(0);
	
	
})

*/

//$j('#comparting-2010-registration-form').each(function(){
$j('.ce_accordion:first').closest('.mod_article')
	.add('#comparting-form-js')
		.each(function(){



	$j(this).find('fieldset:not(:first, :last, .noacco)').each(function(){
	
		$j(this).addClass('active-slider');
		$jfieldsetContent = $j(this).children();
	
		$jfieldsetContent.filter(':not(legend)').wrapAll('<div class="slide-cnt"><div class="slide-cnt-inner"></div></div>');
		
		$jfieldsetContent.filter('legend').addClass('toggleLabel').click(function(){
			$j(this).children('span').toggleClass('active');
			$j(this).next().slideToggle(400);
		}).wrapInner('<span />');
		
		//.slideToggle();	
	})
	
	$j(this).find('.toggleLabel:first span').addClass('active');	
	$j(this).find('.slide-cnt').slideToggle(0);
	$j(this).find('.slide-cnt:first').slideToggle(0);
	
})



$countryContacts = $j('.region-content');

	
	
$j.fn.updateContacts = function(region){

	//alert(region);

	var $regionContent = (region == undefined) 
	//? $countryContacts 
	? $j('')
	:$j('.'+region+'-content');		
	
	if(($regionContent.length != $countryContacts.length) || ($j('.region-content:not(.invisible)').length != $countryContacts.length)){
		
		$j(this).fadeOut(config.animatespeed, function(){
			$j(this).find('img.region').removeClass('selected').css('display', 'none');			
			$countryContacts.addClass('invisible');		
			$regionContent.removeClass('invisible');
			$j(this).fadeIn(config.animatespeed);
			
			return false;		
		});	
	
	}
	
	
}




jQuery("#map-view-container").each(function(){			
			$mapContainer = $j(this);			
			
			$contactWrapper = $j('<div id="contactWrapper"></div>');			
			$contactInnerWrapper = $j('<div id="countryContact"></div>');			
			$contactWrapper.append($contactInnerWrapper);
				
			$j('#contact').after($contactWrapper);			
			
			$countryContacts.appendTo($contactInnerWrapper);
			
			jQuery(this).find(".map-container AREA")			
				.mouseover(function(){				
					var regionMap = '.'+$j(this).attr('id')+'-map';
					$j(regionMap).stop().css({
						'opacity':'0',
						'display':'block'
					}).animate({opacity:1}, config.animatespeed); 												
				})
				.mouseout(function(){
					var regionMap = '.'+$j(this).attr('id')+'-map';					
					if (! jQuery(regionMap).hasClass('selected')) {
						jQuery(regionMap).stop().fadeOut(config.animatespeed, function(){			$j(regionMap).css({
								'display':'none'							
							})

						});
					}		
				})
				.click(function(){						
				
					$mapContainer.addClass('small');
					var regionMap = '.'+$j(this).attr('id')+'-map';					
					var regionCnt = '.'+$j(this).attr('id')+'-submap';
					$mapContainer.find('.map-container .regionBg').animate({
						'height': '58px',
						'width': '108px'
					},config.animatespeed);
					
					$j(regionCnt).addClass('selected').
						stop()
						.css({'opacity':'0', 'display':'block'})
						.animate({opacity:1}, config.animatespeed);
						
					
					$mapContainer.find('.map-container .regionBg').click(function(){		
						$j(this).animate({
							'height': '292px',
							'width': '545px'
						},config.animatespeed);
						
						$mapContainer.find('.sub-map-container.selected').animate({
							'opacity':0
						}, config.animatespeed, function(){
							$mapContainer.find('.sub-map-container.selected').css('dipslay', 'none');
							$j($mapContainer).removeClass('small');
							$mapContainer.find('.sub-map-container, img.region').removeClass('selected').css({
								'display':'none',
								'opacity': '0'
							});
							
						} )
						
						$contactInnerWrapper.updateContacts();
					
					});
					return false;											
				});
			
			// Submap Code			
			jQuery(this).find(".sub-map-container AREA").mouseover(function(){
				var regionMap = '.'+$j(this).attr('id')+'-submap';
				var regionContent = '.'+$j(this).attr('id')+'-content';
				
				//console.log(regionMap + ' ' + regionContent);
				
					
				
				if (! jQuery(regionMap).hasClass('selected')) {
				
					jQuery(regionMap).siblings(".regionBg").css('opacity', "1");
				
					jQuery(regionMap).stop().css({'display':'block'}).animate({opacity:1}, config.animatespeed); 			
				}
				
			}).mouseout(function(){
				var regionMap = '.'+$j(this).attr('id')+'-submap';
				var regionContent = '.'+$j(this).attr('id')+'-content';
				
				if (! jQuery(regionMap).hasClass('selected')) {
					jQuery(regionMap).stop().animate({opacity:0}, config.animatespeed,function(){
						$j(this).css('display', 'none');
						//alert('test');
					
					
					}); 
				}	

			}).click(function(){				
				var regionMap = '.'+$j(this).attr('id')+'-submap';			
				var regionContent = '.'+$j(this).attr('id')+'-content';				
				
				$j(regionMap).addClass('selected').show();
								
				$contactInnerWrapper.updateContacts($j(this).attr('id'));
				
				$j(regionMap).siblings('.region').removeClass('selected').stop().animate({
					opacity:0
				}, config.animatespeed); 			

				$j(regionContent).addClass('selected').stop().animate({				
					'opacity':'1'
				}, config.animatespeed)		
				
				return false;
			});
			

		});


/*
 * OTRS-Login
 */

//*
var otrsUrl = 'https://www.compart.com/otrs/customer.pl';
  
$j('#tl_login').each(function(){	
	
	var $loginForm = $j(this); 	
	$j(this).find('.submit').click(function(){
		var otrsloginUser = $loginForm.find('#username').val();
		var otrsloginPass = $loginForm.find('#password').val();		
		
		$j.post(otrsUrl, { 
	 		"Action": 'Login',
			"User": otrsloginUser, 
			"Password": otrsloginPass,
      "Lang": location.href.split("/")[3]
		}, function(data) {
			$loginForm.submit(); 		  
		}); 		
		return false; 	
	}) 
})	
  
$j('#header .button[title="Logout"]').click(function(){	
	$j.post(otrsUrl, { 
		"Action": 'Logout'
	}, function(data) {});
	
})
// */
 
/**
 * Language Selection Dropdown
 *
 */
 
//*
       
$j('.dropdown').each(function(){

	$dropDownCnt = $j(this);
	$dropDownCnt.find("dt a").click(function() {
		$j(this).parent().parent().toggleClass('active');
	    //$dropDownCnt.find("dd ul");
	    return false
	});   	
	$j(this).find("dd a").click(function() {
	    var text = $j(this).html();
	    $j(".dropdown dt a span").html(text);
	    $j(".dropdown dd ul").hide();
	    
	    //alert('/'+$j(this).attr('href'));
	    
	    window.location.href = '/'+$j(this).attr('href');	    	    
	    return false;
	});	
})



// */




/**
 * Does some voodo stuff when a big upload is submitted
 */

$j('#cUpload').submit(function(){

  $j('#cUpload').css('display', 'none');
  $j('#cUploadInfo').css('display', 'none');
  $j('#cUploadProgress').css('display', 'block');

})

function doIframe(){
	o = document.getElementsByTagName('iframe');
	for(i=0;i<o.length;i++){
		if (/\bautoHeight\b/.test(o[i].className)){
			setHeight(o[i]);
			addEvent(o[i],'load', doIframe);
		}
	}		
}
function setHeight(e){

//*

	if(e.contentDocument){
		//e.height = e.contentDocument.getElementById('main').offsetHeight + 150;
		e.height = e.contentDocument.body.offsetHeight;
	} else {
		e.height = e.contentWindow.document.body.scrollHeight;
	}

//*/
	
/*
	if (e.Document && e.Document.body.scrollHeight) {//ie5+ syntax
	e.height = e.contentWindow.document.body.scrollHeight;
	}
	else if (e.contentDocument && e.contentDocument.body.scrollHeight){ //ns6+ & opera syntax
	e.height = e.contentDocument.body.scrollHeight + 35; }
	
	else (e.contentDocument && e.contentDocument.body.offsetHeight){ //standards compliant syntax ie8
	e.height = e.contentDocument.body.offsetHeight + 35;
	}
	
//*/	
	
	
}







function addEvent(obj, evType, fn){
	if(obj.addEventListener)
	{
		obj.addEventListener(evType, fn,false);
		return true;
	}else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	}else {
		return false;
	}
}



if (document.getElementById && document.createTextNode){
 addEvent(window,'load', doIframe);	
}


});

