// JavaScript Document
$(document).ready(function(){
// image gallery
  htmlStr = "<a href='javascript:void(0)' class='imageGalleryThunbnailsBG'><div></div></a>";
  $(".imageGalleryThunbnails img").wrap(htmlStr).click(function(){
    $(".imageGalleryImage img").attr("src", $(this).attr("zoomLargeUrl"));
    $(".imageGalleryImage img").attr("zoomParam", $(this).attr("zoomGalleryParam"));
    $(".imageGalleryImage img").attr("zoomurl", $(this).attr("zoomGalleryUrl"));
    $(".imageGalleryThunbnailsBG div").css("backgroundImage", "none");
    $(this).parent().css("height", "56px");
    $(this).parent().css("backgroundImage", "url(/corweb/images/galerie_thumb_bg-a.jpg.jpg )");
  });
}); // document.ready

//jq transform
$(function() {
    $("form.jqtransform").jqTransform();
	
	//menu
	$("#ddtabs2 li").click(function(){
		$("#ddtabs2 li a").removeClass("selected");
		$("a",this).addClass("selected");
		$("div.tabcontent").hide();
		var id = "#" + $("a",this).attr("rel");
		$(id).show();
	})
	//enable selected menu
	$("#ddtabs2 li a.selected").parent().trigger("click");
});

$(function(){
	//author slides
	$('.slides').cycle({
		fx:     'fade',
		speed:  'slow',
		random: 1,
		timeout: 0, /* milisecunde */
		next:   '.slider_arrow_right', 
		prev:   '.slider_arrow_left',
		cleartype:  false
	});
	//activate img click
	$('div.slider_image img').click(function(){
		$('.slides').cycle('next');
	});	
	
	//menu		
	$("ul.menu1 > li > a").click( function(ev){
		var clickDiv = $("div",$(this).parent());
		var prevDiv = $("ul.menu1 > li > div:visible");		
		if(clickDiv.css("position")!="absolute")
		{
			clickDiv.css("position","absolute");
			clickDiv.css("margin-top", -(clickDiv.height() + 2) );
		}		
		prevDiv.hide();
		if( clickDiv.get(0) == prevDiv.get(0) )
		{
			clickDiv.hide();
			
			if( $(this).attr("otext") !=null )
				$(this).html($(this).attr("otext"));

			clickDiv.parent().removeClass("close").addClass("share");
			return;
		}
		
		clickDiv.show();		
		if( $(this).attr("otext") == null )//save old text
			$(this).attr("otext", $(this).html());
		$(this).html("- Layer schliessen");
			
		$(this).parent().removeClass("share").addClass("close");
	})
	
});
	

$(function () {
	//homepage slides
	if( typeof($.fn.slides) == 'function' )
	{
		$('#slides').slides({
			preload: false,
			preloadImage: 'images/loading.gif',
			play: 6000,
			pause: 10,
			fadeSpeed: 900,
			effect: 'fade',
			hoverPause: true,
			animationStart: function (current) {
				$('.caption').eq(current - 1).animate({
					bottom: -35
				}, 100);

				$(".pagination li a").eq(current - 1).fadeTo(800, 0.35);
				
				if (window.console && console.log) {
					// example return of current slide number
					console.log('animationStart on slide: ', current);
				};
			},
			animationComplete: function (current) {
				$('.caption').eq(current - 1).animate({
					bottom: 0
				}, 200);
				
				$(".pagination li a").eq(current - 1).fadeTo(800, 1);
				
				if (window.console && console.log) {
					// example return of current slide number
					console.log('animationComplete on slide: ', current);
				};
			},
			slidesLoaded: function () {	
				$('.caption').animate({
					bottom: 0
				}, 200);
			}
		});
		clearTypeFix( $('#slides .slide .caption a') );
		$(".pagination li a").eq(0).fadeTo(800, 1);
	}
});

function clearTypeFix($slides) {
	function hex(s) {
		s = parseInt(s).toString(16);
		return s.length < 2 ? '0'+s : s;
	};
	function getBg(e) {
		for ( ; e && e.nodeName.toLowerCase() != 'html'; e = e.parentNode) {
			var v = $.css(e,'background-color');
			if (v && v.indexOf('rgb') >= 0 ) {
				var rgb = v.match(/\d+/g);
				return '#'+ hex(rgb[0]) + hex(rgb[1]) + hex(rgb[2]);
			}
			if (v && v != 'transparent')
				return v;
		}
		return '#f1f2f2';
	};
	function removeFilter(el) {
		if (!$.support.opacity && el.style.filter) {
			try { el.style.removeAttribute('filter'); }
			catch(smother) {} // handle old opera versions
		}
	};
	
	$slides.each(function() { removeFilter(this); $(this).css('background-color', '#EFEFEF'); });
};


/***********************************************
* Floating Top Bar script- Â© Dynamic Drive (www.dynamicdrive.com)
* Sliding routine by Roy Whittle (http://www.javascript-fx.com/)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var startX = 30 //set x offset of bar in pixels
var startY = 0 //set y offset of bar in pixels
var verticalpos="frombottom" //enter "fromtop" or "frombottom"
function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function staticbar(){
	barheight=document.getElementById("topbar").offsetHeight
	var ns = (navigator.appName.indexOf("Netscape") != -1) || window.opera;
	var d = document;
	function ml(id){
		var el=d.getElementById(id);
		el.style.visibility="visible"
		if(d.layers)el.style=el;
		el.sP=function(x,y){/*this.style.left=x+"px";*/this.style.top=y+"px";};
		//el.x = startX;
		if (verticalpos=="fromtop")
		el.y = startY;
		else{
		el.y = ns ? pageYOffset + innerHeight : iecompattest().scrollTop + iecompattest().clientHeight;
		el.y -= startY;
		}
		return el;
	}
	window.stayTopLeft=function(){
		if (verticalpos=="fromtop"){
		var pY = ns ? pageYOffset : iecompattest().scrollTop;
		ftlObj.y += (pY + startY - ftlObj.y)/1;
		}
		else{
		var pY = ns ? pageYOffset + innerHeight - barheight: iecompattest().scrollTop + iecompattest().clientHeight - barheight;
		ftlObj.y += (pY - startY - ftlObj.y)/1;
		}
		ftlObj.sP(ftlObj.x, ftlObj.y);
		setTimeout("stayTopLeft()", 10);
	}
	ftlObj = ml("topbar");
	stayTopLeft();
}
$(function(){
	var ua = navigator.userAgent;
	var isiOs = /iPad/i.test(ua) || /iPhone/i.test(ua);
	if( isiOs )
		staticbar();
})

