/* Stadtwerke KH */
/* B. Pitule
 * 25.11.11
 */


/* SUCHE */
function SuchBox(SuchBoxInitVal) {
  
  var OBJ = jQuery('#sword');
  OBJ.val(SuchBoxInitVal);
  /* Suchbox Value �ndern onFocus*/
  OBJ.focus(function () {
    if (OBJ.val()==SuchBoxInitVal) {
      OBJ.val('');
    }
  });
  OBJ.blur(function () {
    if (OBJ.val()==='') {
      OBJ.val(SuchBoxInitVal);
    }
  });

  jQuery('#searchButton').focus(function() {
    blur();
  });

  jQuery('#search').submit(function() {
    return true;
  });

} /* eof SuchBox */

/* NewsTeaser */
function initTeaser() {

  jQuery('#NewsTeaser').mouseenter(function() {

    jQuery('#NewsTeaser').animate({
      left: '0'
    }, {
      duration: 500,
      specialEasing: {
        left: 'easeInOutQuart'
      },
      complete: function() {

        jQuery('#NewsTeaserToggle').click(function(){
          sleepTeaser();
        });

      /*
         jQuery('#NewsTeaser').mouseleave(function(){
          window.setTimeout('sleepTeaser()', 1500);
        });
         */
      }

    });
  });

  fadeNewsTeaser();

}
function sleepTeaser() {
  jQuery('#NewsTeaser').animate({
    left: '-220'
  }, {
    duration: 500,
    specialEasing: {
      left: 'easeOutBack'
    },
    complete: function() {}
  });
}
function fadeNewsTeaser() {

  var FaderContainer = jQuery('#NewsTeaserContent  .news-latest-container');
  FaderContainer.innerfade({
    'animationtype':    'fade',
    'speed':            '750',
    'type':             'sequence',
    'timeout':          3500,
    'containerheight':  '108',
    'runningclass':     'innerfade',
    'children':         null
  });

}

function myMenu() {
  
  jQuery('#swkhMenu').dcMegaMenu({
    rowItems: '4',
    speed: 'fast',
    effect: 'slide',
    fullWidth: false,
    onLoad : function(){
      jQuery(this).find(".sub-container").width(680);
    }
  });

  jQuery('.dc-mega-icon').remove();
  
}

function Stickies() {

  var myTopBar = new expstickybar({
    id: "headerContainer", //id of sticky bar DIV
    position:'top', //'top' or 'bottom'
    revealtype:'mouseover', //'mouseover' or 'manual'
    peekamount:44, //number of pixels to reveal when sticky bar is closed
    externalcontent:'', //path to sticky bar content file on your server, or "" if content is defined inline on the page
    speed:500 //duration of animation (in millisecs)
  });

  var mystickybar = new expstickybar({
    id: "stickybar", //id of sticky bar DIV
    position:'bottom', //'top' or 'bottom'
    revealtype:'mouseover', //'mouseover' or 'manual'
    peekamount:28, //number of pixels to reveal when sticky bar is closed
    externalcontent:'', //path to sticky bar content file on your server, or "" if content is defined inline on the page
    speed:500 //duration of animation (in millisecs)
  });

  var myPersonUnten = new expstickybar({
    id: "PersonUnten", //id of sticky bar DIV
    position:'bottom', //'top' or 'bottom'
    revealtype:'mouseover', //'mouseover' or 'manual'
    peekamount:240, //number of pixels to reveal when sticky bar is closed
    externalcontent:'', //path to sticky bar content file on your server, or "" if content is defined inline on the page
    speed:500 //duration of animation (in millisecs)
  });

  jQuery('#PersonUnten').click(function() {
    jQuery(this).fadeOut(500);
  })
  
}

function OrangeFleck() {
  /* orangener Fleck */
  jQuery('div.slider-wrapper').append('<div id="OrangeViereck"></div>');
/*
    jQuery('#OrangeViereck').mouseenter(function() {
    jQuery(this).animate({
      'width':400,
      'height':128
    }, {
      duration: 500,
      specialEasing: {
        left: 'easeOutBack'
      },
      complete: function() {}
    });
  });

  jQuery('#OrangeViereck').mouseleave(function() {
    jQuery(this).animate({
      'width':48,
      'height':48
    }, {
      duration: 500,
      specialEasing: {
        left: 'easeOutBack'
      },
      complete: function() {}
    });
  });
   */
}
var intVal_loadbalancing=0;
var Objs = new Array(
  'initTeaser();',
  'Stickies();'
  );
function loadBalancing() {

  /*
   *alert('loadgebalanced: '+intVal_loadbalancing);
   */
     
  if(intVal_loadbalancing<=Objs.length-1) {
    eval(Objs[intVal_loadbalancing]);
    intVal_loadbalancing++;
    window.setTimeout('loadBalancing()',250);

  } else {
/*
     *alert('loadBalancing() : ende');
     */
}

}

function KontaktPops() {
  /* Simple: Fancyboxed */
  /*
   *jQuery("a[target='kontaktPop']").addClass('jqfancybox');
  */
  jQuery("a[target='kontaktPop']").bind({
    mouseover: function() {
      if(jQuery('#imgPop').length<1) {
        jQuery(this).parent().parent().parent().prepend('<div id="imgPop" style="position: relative; float:right; display:none;"><img width="150" src="'+jQuery(this).attr('href')+'" /></div>');
        jQuery('#imgPop').fadeIn(250);
      }
    },
    mouseout: function() {
      jQuery('#imgPop').remove();
    }
  });
}

/*
 *Onload
 */

jQuery(document).ready(function() {

  myMenu();
  
  window.setTimeout('loadBalancing()',50);

  SuchBox('Webseite durchsuchen');

  /* Contracting */
  jQuery('span.ContractingFilm').fancybox();

  OrangeFleck();

  AccordionMenu();

  KontaktPops();

});

function AccordionMenu() {
  var icons = {
    header: "collapsed",
    headerSelected: "expanded"
  };
  jQuery('.accordionMenu').accordion({
    autoHeight: false,
    navigation: true,
    collapsible: true,
    icons: icons
  });
}

		var browserName = navigator.appName;
		var browserVer = parseInt(navigator.appVersion);
		var version = "";
		var msie4 = (browserName == "Microsoft Internet Explorer" && browserVer >= 4);
		if ((browserName == "Netscape" && browserVer >= 3) || msie4 || browserName=="Konqueror" || browserName=="Opera") {version = "n3";} else {version = "n2";}
			// Blurring links:
		function blurLink(theObject)	{	//
			if (msie4)	{theObject.blur();}
		}
		
			// decrypt helper function
		function decryptCharcode(n,start,end,offset)	{
			n = n + offset;
			if (offset > 0 && n > end)	{
				n = start + (n - end - 1);
			} else if (offset < 0 && n < start)	{
				n = end - (start - n - 1);
			}
			return String.fromCharCode(n);
		}
			// decrypt string
		function decryptString(enc,offset)	{
			var dec = "";
			var len = enc.length;
			for(var i=0; i < len; i++)	{
				var n = enc.charCodeAt(i);
				if (n >= 0x2B && n <= 0x3A)	{
					dec += decryptCharcode(n,0x2B,0x3A,offset);	// 0-9 . , - + / :
				} else if (n >= 0x40 && n <= 0x5A)	{
					dec += decryptCharcode(n,0x40,0x5A,offset);	// A-Z @
				} else if (n >= 0x61 && n <= 0x7A)	{
					dec += decryptCharcode(n,0x61,0x7A,offset);	// a-z
				} else {
					dec += enc.charAt(i);
				}
			}
			return dec;
		}
			// decrypt spam-protected emails
		function linkTo_UnCryptMailto(s)	{
			location.href = decryptString(s,-1);
		}
		
jQuery(document).ready(function() {
	jQuery('#imagecycle-nivo_c632').parent().show();
	jQuery('#imagecycle-nivo_c632').nivoSlider({
		effect: 'slideInLeft,fade,slideInRight',
		prevText: 'prev',
		nextText: 'next',
		slices: 15,
		boxCols: 8,
		boxRows: 4,
		animSpeed: 450,
		pauseTime: 6800,
		captionOpacity: '0.8',
		directionNav: false,
		directionNavHide: false,
		controlNav: false,
		keyboardNav: false,
		pauseOnHover: true,
		manualAdvance: false
	});
});

/*Expandable Sticky Bar (Initial: Nov 1st, 2010)
* This notice must stay intact for usage 
* Author: Dynamic Drive at http://www.dynamicdrive.com/
* Visit http://www.dynamicdrive.com/ for full source code
*/

//jQuery.noConflict()

function expstickybar(usersetting){
	var setting=jQuery.extend({position:'bottom', peekamount:25, revealtype:'mouseover', speed:400}, usersetting)
	var thisbar=this
	var cssfixedsupport=!document.all || document.all && document.compatMode=="CSS1Compat" && window.XMLHttpRequest //check for CSS fixed support
	if (!cssfixedsupport || window.opera)
		return
	jQuery(function($){ //on document.ready
		if (setting.externalcontent){
			thisbar.$ajaxstickydiv=$('<div id="ajaxstickydiv_'+setting.id+'"></div>').appendTo(document.body) //create blank div to house sticky bar DIV
			thisbar.loadcontent($, setting)
			}
		else
			thisbar.init($, setting)
	})
}

expstickybar.prototype={

	loadcontent:function($, setting){
		var thisbar=this
		var ajaxfriendlyurl=setting.externalcontent.replace(/^http:\/\/[^\/]+\//i, "http://"+window.location.hostname+"/") 
		$.ajax({
			url: ajaxfriendlyurl, //path to external content
			async: true,
			error:function(ajaxrequest){
				alert('Error fetching Ajax content.<br />Server Response: '+ajaxrequest.responseText)
			},
			success:function(content){
				thisbar.$ajaxstickydiv.html(content)
				thisbar.init($, setting)
			}
		})

	},

	showhide:function(keyword, anim){
		var thisbar=this, $=jQuery
		var finalpx=(keyword=="show")? 0 : -(this.height-this.setting.peekamount)
		var positioncss=(this.setting.position=="bottom")? {bottom:finalpx} : {top:finalpx}
		this.$stickybar.stop().animate(positioncss, (anim)? this.setting.speed : 0, function(){
			thisbar.$indicators.each(function(){
				var $indicator=$(this)
				$indicator.attr('src', (thisbar.currentstate=="show")? $indicator.attr('data-closeimage') : $indicator.attr('data-openimage'))
			})
		})
		
		thisbar.currentstate=keyword
	},

	toggle:function(){
		var state=(this.currentstate=="show")? "hide" : "show"
		this.showhide(state, true)
	},

	init:function($, setting){
		var thisbar=this
		this.$stickybar=$('#'+setting.id).css('visibility', 'visible')
		this.height=this.$stickybar.outerHeight()
		this.currentstate="hide"
		if (setting.revealtype=="manual") {
			this.currentstate="show"
		}
		setting.peekamount=Math.min(this.height, setting.peekamount)
		this.setting=setting
		if (setting.revealtype=="mouseover")
			this.$stickybar.bind("mouseenter mouseleave", function(e){
				thisbar.showhide((e.type=="mouseenter")? "show" : "hide", true)
		})
		this.$indicators=this.$stickybar.find('img[data-openimage]') //find images within bar with data-openimage attribute
		this.$stickybar.find('a[href=#togglebar]').click(function(){ //find links within bar with href=#togglebar and assign toggle behavior to them
			thisbar.toggle()
			return false
		})
		setTimeout(function(){
			thisbar.height=thisbar.$stickybar.outerHeight() //refetch height of bar after 1 second (last change to properly get height of sticky bar)
		}, 1000)
		this.showhide("hide")
		if (setting.revealtype=="manual") {
			this.showhide("show")
		}
	}
}


/////////////Initialization code://///////////////////////////

//Usage: var unqiuevar=new expstickybar(setting)
/*
var mystickybar=new expstickybar({
	id: "stickybar", //id of sticky bar DIV
	position:'bottom', //'top' or 'bottom'
	revealtype:'mouseover', //'mouseover' or 'manual'
	peekamount:25, //number of pixels to reveal when sticky bar is closed
	externalcontent:'', //path to sticky bar content file on your server, or "" if content is defined inline on the page
	speed:400 //duration of animation (in millisecs)
})
*/

/* <![CDATA[ */
			jQuery.noConflict();
			(function($) {
				$(document).ready(function() {
				if ($("*").is(".jqfancybox")) {
						$(".jqfancybox").fancybox({
							"padding": 0,
							"speedIn": 300,
							"speedOut": 300,
							"changeSpeed": 300,
							"transitionIn": "elastic",
							"transitionOut": "elastic",
							"titlePosition": "over",
							"titleShow": true,
							"easingIn": "swing",
							"easingOut": "swing",
							"showCloseButton": true,
							"showNavArrows": true,
							"enableEscapeButton": true,
							"overlayShow": true,
							"overlayOpacity": 0.4,
							"overlayColor": "#666",
							"centerOnScroll": false,
							"hideOnContentClick": false,
							"onComplete"		 :	function() {
														$("#fancybox-wrap").hover(function() {
															$("#fancybox-title").show();
														}, function() {
															$("#fancybox-title").hide();
														});
												 	},  "titleFormat": function(title, currentArray, currentIndex, currentOpts) { return '<span id="fancybox-title-over">Bild ' + (currentIndex + 1) + ' von ' + currentArray.length + (title.length ? ' : &nbsp; ' + title : '') + '</span>';}
				});
			 }
			});})(jQuery);
			/* ]]> */

