jQuery.noConflict();

	// ------ global functions

	function stop(e) {
	   if (!e) e = window.event;
	   (e.stopPropagation) ? e.stopPropagation() : e.cancelBubble = true;
	   (e.preventDefault) ? e.preventDefault() : e.returnValue = false;
	   return false;
	}

	function prevDef(e) {
	   if (!e) e = window.event;
	   (e.preventDefault) ? e.preventDefault() : e.returnValue = false;
	   return false;
	}

	function log(message) {
	   if (typeof console != 'undefined' && typeof console.log != 'undefined') { console.log(message) }
	};
	function info(message) {
	   if (typeof console != 'undefined' && typeof console.info != 'undefined') { console.info(message) }
	};
	function warn(message) {
	   if (typeof console != 'undefined' && typeof console.warn != 'undefined') { console.warn(message) }
	};

	function findEventTag(e) {
		var targ;
		if (!e) var e = window.event;
		if (e.target) targ = e.target;
		else if (e.srcElement) targ = e.srcElement;
		if (targ.nodeType == 3) // defeat Safari bug
			targ = targ.parentNode;
		return targ
	}

	function urlHash(param) {
		location.href = location.href.split("#")[0] + "#" + param;
	}

	function cleanHash() {
		location.href = location.href.split("#")[0]+"#home";
	}

	function hashLoad() {
		var hashString = location.href;
		var hashVars = new Array();

		var lastchar = hashString[hashString.length - 1]

		if ((lastchar != "#") && (lastchar != "=")) {

			hashString = hashString.split("#")[1];
			if (hashString != undefined) {
				pair = hashString.split("=");
				return pair;
			}
		}
	}

	//on page load
	jQuery(document).ready(function () {

		if (jQuery("body").hasClass("noJs")) {
			jQuery("body").removeClass("noJs").addClass("activeJs");
		}
		jQuery('input','.form').each(function(){jQuery(this).addPlaceholder()});

		//start slideShow
		jQuery("#slideShow").each(function(){jQuery(this).initSlideShow()})

		//prettify footer
		jQuery("#footer").each(function() {
			var footerwidth = jQuery(this).width();
			var cols = jQuery(this).find('ul').length;
			var padding = jQuery('ul',this).outerWidth(true) - jQuery('ul',this).width() + 1;
			var restfooter = (footerwidth)-padding*cols;
			jQuery('ul',this).each(function(){jQuery(this).css('width',(restfooter/cols))});
		});
	});

	// Placeholder function
	jQuery.fn.addPlaceholder = function(val) {

		  //abort function if type of input is not 'text' or placeholder attribute is already supported by browser

		  if (jQuery(this).attr('type')!="text" || phsupported()) {
				return false;
		  }
		  else {
				var phvalue = jQuery(this).attr('placeholder');
				//check if value isFinite passed by updatepanel
				if (val != null) { phvalue = val }
				jQuery(this).attr('value',phvalue);
				jQuery(this).bind("focus", {lblValue: phvalue}, inputfocus);
				jQuery(this).bind("blur", {lblValue: phvalue}, inputblur);
		  }
		  function inputfocus(event) {if(this.value == event.data.lblValue) this.value='';};
		  function inputblur(event) {if(this.value=='') this.value=event.data.lblValue;};
		  //helper function to check if browser supports placeholder attribute
		  function phsupported() {
				var el = document.createElement('input');
				return 'placeholder' in el;
		  }
	}


	jQuery.fn.initSlideShow = function() {

		var slideShow = jQuery(this);
		var slideWidth = slideShow.width();

		//calculate canvas width
		var totalslides= jQuery(".slide",slideShow).length-1;
		var canvasWidth = -(totalslides-1)*slideWidth;
		var slideSpeed = 1;
		var WaitTime = 10;
		var timeUnit = 600; //timeUnit = seconds
		var speed = slideSpeed * timeUnit;
		var slideTimer = null;
		var activeSlide = 0; //which slide is active
		var loop = "true";
		var indexmode = "thumb"; // [number|image|thumb] default="number"

		//init directaccess ----------

		jQuery(".slide",slideShow).each(function(i){
			checklink(this);
			jQuery(this).show();
			var indexlist = jQuery(document.createElement('li'));
			var indexlink = jQuery(document.createElement('a')).attr('href','javascript:void(0)');
			var indexbutton;
			if (indexmode=="thumb") { indexbutton = indexlist.append(indexlink.append(jQuery(".slider-bg",jQuery(this)).clone())); }
			else { indexbutton = indexlist.append(indexlink.append(i));	}
			jQuery(".directaccess ul").append(indexbutton);
		})

		var thumbWidth = jQuery(".directaccess li",slideShow).outerWidth();

		jQuery(".directaccess a").bind("click",function(e){
			stop(e);
			var position = jQuery(".directaccess a").index(jQuery(this));
			slide(position);
		})

		if (loop == "true") {
			jQuery("#canvas", slideShow).append(jQuery(".slide:first",slideShow).clone());
		}

		//helper function to add link to slide image

		function checklink(slide) {
			var thelink = jQuery('a.slidelink',slide);
			if (!thelink.length) {return false}
			var slidelink = jQuery(thelink).attr('href');
			if (slidelink != '') {
				jQuery(slide).find('img').css({'cursor':'hand','cursor':'pointer'}).click(function(e) {
					window.open(slidelink);
					return false;
				});
			}
		}

		//init nextPrev ----------

		slideShow.bind("mouseenter", function () {
			jQuery(".prevnext",slideShow).fadeIn(350);
			clearInterval(slideTimer)
		});

		slideShow.bind("mouseleave", function () {
			jQuery(".prevnext",slideShow).fadeOut(50);
			clearInterval(slideTimer);
			autoplay();
		});

		jQuery(".next",slideShow).bind("click",function(e){slideNext();});
		jQuery(".prev",slideShow).bind("click",function(e){slidePrev();});

		//init slide magic ----------

		function autoplay()  {
			slideTimer = setInterval(function(){slideNext()},WaitTime * timeUnit)
		}

		function slideNext() {
			if (activeSlide<totalslides) {slide(activeSlide+1)}
			else {
				if (loop == "true") {loopslide()}
				else {slide(0)}
			}
		}

		function slidePrev() {
			if (activeSlide==0) {slide(totalslides)}
			else {slide(activeSlide-1)}
		}

		function slide(pos) {
			jQuery("#canvas",slideShow).animate({"margin-left":-slideWidth*pos},speed/2);
			jQuery(".current",slideShow).animate({"margin-left":pos*thumbWidth},timeUnit/2);
			activeSlide = pos;
		}
		function loopslide() {
			jQuery("#canvas",slideShow).animate({"margin-left":-slideWidth*(activeSlide+1)},speed/2,function(){jQuery("#canvas",slideShow).css({"margin-left":0})})
			jQuery(".current",slideShow).animate({"margin-left":0},timeUnit/2);
			activeSlide = 0;
		}

		//start the show
		autoplay();
	}

