/*
* Slides, A Slideshow Plugin for jQuery
* Intructions: http://slidesjs.com
* By: Nathan Searles, http://nathansearles.com
* Version: 1.1.8
* Updated: June 1st, 2011
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
(function(A){A.fn.slides=function(B){B=A.extend({},A.fn.slides.option,B);return this.each(function(){A("."+B.container,A(this)).children().wrapAll('<div class="slides_control"/>');var V=A(this),J=A(".slides_control",V),Z=J.children().size(),Q=J.children().outerWidth(),M=J.children().outerHeight(),D=B.start-1,L=B.effect.indexOf(",")<0?B.effect:B.effect.replace(" ","").split(",")[0],S=B.effect.indexOf(",")<0?L:B.effect.replace(" ","").split(",")[1],O=0,N=0,C=0,P=0,U,H,I,X,W,T,K,F;function E(c,b,a){if(!H&&U){H=true;B.animationStart(P+1);switch(c){case"next":N=P;O=P+1;O=Z===O?0:O;X=Q*2;c=-Q*2;P=O;break;case"prev":N=P;O=P-1;O=O===-1?Z-1:O;X=0;c=0;P=O;break;case"pagination":O=parseInt(a,10);N=A("."+B.paginationClass+" li."+B.currentClass+" a",V).attr("href").match("[^#/]+$");if(O>N){X=Q*2;c=-Q*2;}else{X=0;c=0;}P=O;break;}if(b==="fade"){if(B.crossfade){J.children(":eq("+O+")",V).css({zIndex:10}).fadeIn(B.fadeSpeed,B.fadeEasing,function(){if(B.autoHeight){J.animate({height:J.children(":eq("+O+")",V).outerHeight()},B.autoHeightSpeed,function(){J.children(":eq("+N+")",V).css({display:"none",zIndex:0});J.children(":eq("+O+")",V).css({zIndex:0});B.animationComplete(O+1);H=false;});}else{J.children(":eq("+N+")",V).css({display:"none",zIndex:0});J.children(":eq("+O+")",V).css({zIndex:0});B.animationComplete(O+1);H=false;}});}else{J.children(":eq("+N+")",V).fadeOut(B.fadeSpeed,B.fadeEasing,function(){if(B.autoHeight){J.animate({height:J.children(":eq("+O+")",V).outerHeight()},B.autoHeightSpeed,function(){J.children(":eq("+O+")",V).fadeIn(B.fadeSpeed,B.fadeEasing);});}else{J.children(":eq("+O+")",V).fadeIn(B.fadeSpeed,B.fadeEasing,function(){if(A.browser.msie){A(this).get(0).style.removeAttribute("filter");}});}B.animationComplete(O+1);H=false;});}}else{J.children(":eq("+O+")").css({left:X,display:"block"});if(B.autoHeight){J.animate({left:c,height:J.children(":eq("+O+")").outerHeight()},B.slideSpeed,B.slideEasing,function(){J.css({left:-Q});J.children(":eq("+O+")").css({left:Q,zIndex:5});J.children(":eq("+N+")").css({left:Q,display:"none",zIndex:0});B.animationComplete(O+1);H=false;});}else{J.animate({left:c},B.slideSpeed,B.slideEasing,function(){J.css({left:-Q});J.children(":eq("+O+")").css({left:Q,zIndex:5});J.children(":eq("+N+")").css({left:Q,display:"none",zIndex:0});B.animationComplete(O+1);H=false;});}}if(B.pagination){A("."+B.paginationClass+" li."+B.currentClass,V).removeClass(B.currentClass);A("."+B.paginationClass+" li:eq("+O+")",V).addClass(B.currentClass);}}}function R(){clearInterval(V.data("interval"));}function G(){if(B.pause){clearTimeout(V.data("pause"));clearInterval(V.data("interval"));K=setTimeout(function(){clearTimeout(V.data("pause"));F=setInterval(function(){E("next",L);},B.play);V.data("interval",F);},B.pause);V.data("pause",K);}else{R();}}if(Z<2){return ;}if(D<0){D=0;}if(D>Z){D=Z-1;}if(B.start){P=D;}if(B.randomize){J.randomize();}A("."+B.container,V).css({overflow:"hidden",position:"relative"});J.children().css({position:"absolute",top:0,left:J.children().outerWidth(),zIndex:0,display:"none"});J.css({position:"relative",width:(Q*3),height:M,left:-Q});A("."+B.container,V).css({display:"block"});if(B.autoHeight){J.children().css({height:"auto"});J.animate({height:J.children(":eq("+D+")").outerHeight()},B.autoHeightSpeed);}if(B.preload&&J.find("img:eq("+D+")").length){A("."+B.container,V).css({background:"url("+B.preloadImage+") no-repeat 50% 50%"});var Y=J.find("img:eq("+D+")").attr("src")+"?"+(new Date()).getTime();if(A("img",V).parent().attr("class")!="slides_control"){T=J.children(":eq(0)")[0].tagName.toLowerCase();}else{T=J.find("img:eq("+D+")");}J.find("img:eq("+D+")").attr("src",Y).load(function(){J.find(T+":eq("+D+")").fadeIn(B.fadeSpeed,B.fadeEasing,function(){A(this).css({zIndex:5});A("."+B.container,V).css({background:""});U=true;B.slidesLoaded();});});}else{J.children(":eq("+D+")").fadeIn(B.fadeSpeed,B.fadeEasing,function(){U=true;B.slidesLoaded();});}if(B.bigTarget){J.children().css({cursor:"pointer"});J.children().click(function(){E("next",L);return false;});}if(B.hoverPause&&B.play){J.bind("mouseover",function(){R();});J.bind("mouseleave",function(){G();});}if(B.generateNextPrev){A("."+B.container,V).after('<a href="#" class="'+B.prev+'">Prev</a>');A("."+B.prev,V).after('<a href="#" class="'+B.next+'">Next</a>');}A("."+B.next,V).click(function(a){a.preventDefault();if(B.play){G();}E("next",L);});A("."+B.prev,V).click(function(a){a.preventDefault();if(B.play){G();}E("prev",L);});if(B.generatePagination){if(B.prependPagination){V.prepend("<ul class="+B.paginationClass+"></ul>");}else{V.append("<ul class="+B.paginationClass+"></ul>");}J.children().each(function(){A("."+B.paginationClass,V).append('<li><a href="#'+C+'">'+(C+1)+"</a></li>");C++;});}else{A("."+B.paginationClass+" li a",V).each(function(){A(this).attr("href","#"+C);C++;});}A("."+B.paginationClass+" li:eq("+D+")",V).addClass(B.currentClass);A("."+B.paginationClass+" li a",V).click(function(){if(B.play){G();}I=A(this).attr("href").match("[^#/]+$");if(P!=I){E("pagination",S,I);}return false;});A("a.link",V).click(function(){if(B.play){G();}I=A(this).attr("href").match("[^#/]+$")-1;if(P!=I){E("pagination",S,I);}return false;});if(B.play){F=setInterval(function(){E("next",L);},B.play);V.data("interval",F);}});};A.fn.slides.option={preload:false,preloadImage:"/img/loading.gif",container:"slides_container",generateNextPrev:false,next:"next",prev:"prev",pagination:true,generatePagination:true,prependPagination:false,paginationClass:"pagination",currentClass:"current",fadeSpeed:350,fadeEasing:"",slideSpeed:350,slideEasing:"",start:1,effect:"slide",crossfade:false,randomize:false,play:0,pause:0,hoverPause:false,autoHeight:false,autoHeightSpeed:350,bigTarget:false,animationStart:function(){},animationComplete:function(){},slidesLoaded:function(){}};A.fn.randomize=function(C){function B(){return(Math.round(Math.random())-0.5);}return(A(this).each(function(){var F=A(this);var E=F.children();var D=E.length;if(D>1){E.hide();var G=[];for(i=0;i<D;i++){G[G.length]=i;}G=G.sort(B);A.each(G,function(I,H){var K=E.eq(H);var J=K.clone(true);J.show().appendTo(F);if(C!==undefined){C(K,J);}K.remove();});}}));};})(jQuery);;
/*********************************************************
* 	Created by Clemens Mautner Markhof @ Knallgrau
*	10.6.2011
*	All rights reserved
*	project.js
*	---------------------
*	REQUIRES: jquery >= 1.6.1
*********************************************************/


/*********************************************************
* Team 7 Javascripts
*********************************************************/


/*********************************************************
 * newFunc
 * desc
 *********************************************************/
function newFunc(){

}

var base_path;
var language;

/*********************************************************
 * initSearch
 * PopOut-Search
 *********************************************************/
function initSearch() {
	jQuery('#site-search').mouseover(function() {
		// start slide out animation
		jQuery('#site-search').stop();
		jQuery('#site-search .searchslide').show();
		jQuery('#site-search').animate({
			width: '150px'
		}, 200);
	});
	
	jQuery('#site-search').mouseout(function() {
		// start slide in animation
		jQuery('#site-search').stop();
		jQuery('#site-search').animate({
			width: '30px'
		}, 100, function() {
			jQuery('#site-search .searchslide').hide();
		});
	});
}

/*********************************************************
 * mautiDropDownMenu
 * OSX like drop down menu functionality
 *********************************************************/
function cmmDropDownMenu() {
	
	var lvl1posx = 0;
	var lvl1posy = 0;
	var timer;
	
	//hide if click on 
	/*jQuery(window).click(function(){
		if(jQuery(this).not("#flyout .level-0")) { //only close if click is not on a menu item else load link
			jQuery('#flyout .level-0 li ul').hide();
			jQuery('#flyout .level-0 li').removeClass("active");
		}
	});*/
	
	//hide if cursor leaves flyout menu
	jQuery('#flyout').mouseleave(function() {
		timer = setTimeout(function(){
	        //hide only if cursor stays outside for 1 second
	        jQuery('#flyout .level-0 li').removeClass("active").find('ul').hide();
	    }, 400);
	});
	jQuery("#flyout").mouseover(function(){
	    clearTimeout(timer);
	});
	
	//close menu during resize to avoid glitch
	jQuery(window).resize(function(){
		jQuery('#flyout .level-0 li ul').hide();
		jQuery('#flyout .level-0 li').removeClass("active");
	});
	
	jQuery('#flyout .level-0 li').mouseover(function(){	
		if( jQuery(this).hasClass("active")){
//			console.log("active");
		} else {
//			console.log("noactive");
			var elpos = jQuery(this).position();
			lvl1posx = elpos.left;
			lvl1posy = elpos.top; // space to top menu
			var elheight = jQuery(this).height();
			jQuery('#flyout .level-0 li').removeClass("active");
			jQuery('#flyout .level-0 li').children('ul').hide();
			jQuery(this).children('ul').css({'top':lvl1posy+elheight,'left':lvl1posx}).show();
			jQuery(this).addClass("active");
		}
	});
	
	//show level-2
	jQuery('#flyout .level-1 li').live('mouseover',function(){
//	jQuery('#flyout ul.level-1 > li').mouseover(function(){
		var that = jQuery(this);
//		console.log("mouseover lvl1 li");
		//get position data
		var elpos = that.position();
		var elposx = elpos.left + 10; // position to 2nd level menu
		var elposy = elpos.top;
		var elwidth = that.width();
		var lvl2width = that.children('ul').width();
		
		//1. hide all active fields except the one who is active
		//hide children li as well (IE7 bug)
		that.siblings('li').find('ul.level-2').hide().children('li').hide();
		
		that.addClass("active");
		
		//2. show this one
		//TODO improvement if there is no body min width set it automatically
		//check if there is enough space right else if enough space left show left
//		console.log((that.offset().left+elwidth+lvl2width)+' > '+jQuery(window).width()+' && '+lvl1posx+' >= '+(lvl2width+40));
		if((that.offset().left+elwidth+lvl2width) > jQuery(window).width() && (lvl1posx >= (lvl2width+40))){
			//correct width when less than 4 li elements
			var lis = that.find('ul > li');
			if(lis.size() < 4) {
				lvl2width = lis.size() * lis.first().width();
			}
			lis.addClass('left');
			that.children('ul').css({'left':-lvl2width,'top': 0}).show().children('li').show();
		} else {
			that.children('ul').css({'left':elposx+elwidth,'top': 0}).show().children('li').show().find('li.left').removeClass('left');
		}
//		showLvl2(that);
			
	});
}


/*********************************************************
 * overlay
 * close and open overlays
 *********************************************************/
function overlay_content(htmlid, obj){
  if (!jQuery('#overlay1').is(':hidden')) {
    jQuery('#overlay1').hide();
    return;
  }
  jQuery('#overlay1 #overlay_content').html(jQuery('#'+htmlid).html());
  jQuery('#overlay1').show(0, function() {
    overlay('overlay1', obj); 
  });
  return false;
}

function overlay(id,caller){
	var width = jQuery('#'+id+' .media img').width();
	if (width == null) width = jQuery('#'+id+' .media video').width();
	if (width == null) width = jQuery('#'+id+' .media object').width();
	if (width == null) width = jQuery('#'+id+' .media .flowplayer').width();
	if (width == null) width = jQuery('#' + id + ' .form').width();
	if(width == null) width = 150;
	//console.log("width: "+width);
	
	jQuery('#'+id).width(width);
	var myoffset = jQuery('#main-content').offset();
	var posx = myoffset.left - jQuery('#'+id).outerWidth()/2 + jQuery('#main-content').outerWidth()/2;
	var posy = myoffset.top + 10;
	//if (posy < myoffset.top) {
	//	posy = myoffset.top+10;
	//}
	jQuery('#' + id).css({
		left: posx
	,	top: posy
	});
	if(jQuery('#' + id + ' .flowplayer').length) {
		flowplayer(jQuery('#' + id + ' .flowplayer').attr('id'), flowplayerpath);
	}
	return false;
}

function closeOverlay(close){
	close.parentNode.style.display = 'none';
	return false;
}


/*********************************************************
 * sampleSelect
 * javascript that loads a new larger sample for from a
 * thumbnail
 * larger samples need to be named _large.SUFFIX
 * @PARAM thumb: container id, sample id to change
 * @PARAM optional: nomenklatur for larger samples
 *********************************************************/
function sampleSelect(thumb, sample){
	
	var nomen = "_large";
	
	//optopnal
	if(arguments.length == 3) nomen = arguments[2];
	
	jQuery('#'+thumb+' a').click(function(){
		var img = jQuery(this).find("img").attr('src');
		//get img name without suffix
		var name = img.substr(0,img.length-4);
		var suffix = img.substr(name.length);
		jQuery('#'+sample+' img').attr('src',name+nomen+suffix);
		//set current thumb active
		jQuery('#'+thumb+' a').removeClass("active");
		jQuery(this).addClass("active");
		
		return false;
	});
}



/*********************************************************
 * document.ready
 * app logic
 *********************************************************/
jQuery(document).ready(function(){
	//init placeholder plugin
	jQuery.Placeholder.init();

	//ie doesnt know the placeholder attribute for textboxes -> workaround with value
	if (jQuery.browser.msie ) {
		/*var st = jQuery('#searchtext').attr('placeholder');
		jQuery('#searchtext').val(st).click(function() {
			jQuery(this).val('');
		});*/
		//hide IE7 tooltip showing alt attribute ("Hotspot")
		if (jQuery.browser.version < 8) {
			jQuery('#slides').hover(function() {
				jQuery(this).find('img').attr('alt', '');
			}, function() {
				jQuery(this).find('img').attr('alt', 'Hotspot');
			});
		}
	}
	
    jQuery('#search_button').click(function() {
		jQuery('#search_form').submit();
	});
	jQuery('#search_form').submit(function() {
		window.location.href = base_path+language+'/search_site/'+jQuery('#searchtext').val();
		return false;
	});
	
	//create dropDownMenu
	cmmDropDownMenu();
	
	// initialize search
	initSearch();
	
	//overlay listener
	jQuery('.overlay_close').click(function(){
		closeOverlay(this);
		return false;
	});
	
	//load woodSamples
	//sampleSelect("wood-tiles","wood-sample");
	jQuery("#wood-tiles a").mouseover(function(e){
		var selel = -1;
		var target = e.target;
		jQuery('#wood-tiles').children().find('img').each(function(index,el){
			if(el == target)
			{
				selel = index;
			}
		});
		if(selel >= 0){
                     setWoodActive(selel);
                }
		
		return false;
	});
});

function setWoodActive(selel) {
		jQuery('#wood-tiles a').removeClass("active");
		jQuery('#wood-tiles a:eq('+selel+')').addClass("active");
		jQuery('#wood-selector .desc').addClass('hidden');
		jQuery('#wood-selector .desc:eq('+selel+')').removeClass('hidden');
		jQuery('#wood-selector .woodimg').addClass('hidden');
		jQuery('#wood-selector .woodimg:eq('+selel+')').removeClass('hidden');
}

function showWood(nids) {
        if (nids != 'undefined' && nids.length > 0) {
             for (var ab = 0; ab < nids.length; ab ++) {
                   if (jQuery('#wood-tiles #wood_'+nids[ab]).length) {
                       pos = 0;
                       wpos = -1;
                       jQuery('#wood-tiles li').each(function(){
                           if (jQuery(this).attr('id') == 'wood_'+nids[ab]) {
                              wpos = pos;
                           }
                           pos++;
                       });
                       setWoodActive(wpos);
                   }
             }
        }
}



/*********************************************************
 * Placeholder Plugin
 * used to support the HTML5 placeholder attribute on most non-HTML5-compliant browsers.
 *********************************************************/
(function($){$.Placeholder={settings:{color:"rgb(169,169,169)",dataName:"original-font-color"},init:function(settings){if(settings){$.extend($.Placeholder.settings,settings)};var getContent=function(element){return $(element).val()};var setContent=function(element,content){$(element).val(content)};var getPlaceholder=function(element){return $(element).attr("placeholder")};var isContentEmpty=function(element){var content=getContent(element);return(content.length===0)||content==getPlaceholder(element)};var setPlaceholderStyle=function(element){$(element).data($.Placeholder.settings.dataName,$(element).css("color"));$(element).css("color",$.Placeholder.settings.color)};var clearPlaceholderStyle=function(element){$(element).css("color",$(element).data($.Placeholder.settings.dataName));$(element).removeData($.Placeholder.settings.dataName)};var showPlaceholder=function(element){setContent(element,getPlaceholder(element));setPlaceholderStyle(element)};var hidePlaceholder=function(element){if($(element).data($.Placeholder.settings.dataName)){setContent(element,"");clearPlaceholderStyle(element)}};var inputFocused=function(){if(isContentEmpty(this)){hidePlaceholder(this)}};var inputBlurred=function(){if(isContentEmpty(this)){showPlaceholder(this)}};var parentFormSubmitted=function(){if(isContentEmpty(this)){hidePlaceholder(this)}};$("textarea, input[type='text']").each(function(index,element){if($(element).attr("placeholder")){$(element).focus(inputFocused);$(element).blur(inputBlurred);$(element).bind("parentformsubmitted",parentFormSubmitted);$(element).trigger("blur");$(element).parents("form").submit(function(){$(element).trigger("parentformsubmitted")})}});return this}}})(jQuery);
;

