﻿// JavaScript Document
// Requires jQuery library


$(document).ready(function() {

	
	
	// global settings -------------------
	
	// blur links on focus
	$('a').focus(function() {
		$(this).blur();
	});
	
	$("#sidebarBottom .teaser:last").addClass("lastTeaser");
	
	// enable rollover for IE6
	$(".teaserHome a").hover(
	  function (){$(this).removeClass("reset").addClass("hover");},
	  function (){$(this).removeClass("hover").addClass("reset");}
	);
	$(".carouselNavi a").hover(
	  function (){$(this).removeClass("reset").addClass("hover");},
	  function (){$(this).removeClass("hover").addClass("reset");}
	);
	
	
	// transparency layer height for IE6
	var sidebarRightHeight = $('#main').height();
	if (sidebarRightHeight > 495) {$('#sidebarRight').height(sidebarRightHeight-30);}
	else { $('#sidebarRight').height(465); }
	
	
	
	//initialise dropdown
	$('#primaryNavigation').superfish({
    delay:       200, // delay on mouseout
    animation:   {opacity:'show'},   // an object equivalent to first parameter of jQuery’s .animate() method 
    speed:       1, // faster animation speed 
		autoArrows:  false,  // disable generation of arrow mark-up 
		dropShadows: true   // disable drop shadows 
	});
	
	
	// initialise colorboxes
		
		// colorbox for contactSheet
		$(".contactLnk").colorbox({
		  speed:0,
		  opacity: 0.95,
		  iframe:true, 
		  innerWidth:620, 
		  innerHeight:"75%",
	  	onComplete:function(){ $("body").removeClass("galleryLayer").addClass("frameLayer");}	  	
		});
		
		// colorbox for gallery
	  $(".gallery a").colorbox({
	  	opacity:0.95,	
	  	loop:false,
	  	onComplete:function(){ $("body").removeClass("frameLayer").addClass("galleryLayer");}	  	
	  });
	  $(".floatImage a").colorbox({
	  	opacity:0.95,
	  	loop:false,
	  	onComplete:function(){ $("body").removeClass("frameLayer").addClass("galleryLayer");}	  	
	  });
	  $(".blockImage a").colorbox({
	  	opacity:0.95,
	  	loop:false,
	  	onComplete:function(){ $("body").removeClass("frameLayer").addClass("galleryLayer");}	  	
	  });


	// labeled Inputs 
	// a lable inside the input is displayed & hidden onSelect
	labeledInputs();
	
	// product page javascript settings -------------------
	
	// add functionality to pager links in detail windows
	$('#details .pager a').click(function() {
		
		var pagerItems = $('#details .pager a');
		var numPagerItems = pagerItems.length;
		var contentItems = $('#details').find('.content');
		
		// determine the index of the currently active pager item
		var activePagerIndex = 0;
		
		pagerItems.each(function() {
			if ($(this).hasClass('active')) {
				activePagerIndex = $(this).index();
			}
		});
		
		// determine the index of the pager item that should be set active
		var newPagerIndex = 1;
		
		if ($(this).index() == 0) {
			newPagerIndex = (activePagerIndex > 1) ? (activePagerIndex - 1) : 1;
		}
		else if ($(this).index() == (numPagerItems - 1)) {
			newPagerIndex = (activePagerIndex < numPagerItems - 2) ? (activePagerIndex + 1) : (numPagerItems - 2);
		}
		else {
			newPagerIndex = $(this).index();
		}
		
		if (newPagerIndex == 1) {
			pagerItems.eq(0).addClass('previous-inactive');
		}
		else {
			pagerItems.eq(0).removeClass('previous-inactive');
		}
		
		if (newPagerIndex == (numPagerItems - 2)) {
			pagerItems.eq(numPagerItems - 1).addClass('next-inactive');
		}
		else {
			pagerItems.eq(numPagerItems - 1).removeClass('next-inactive');
		}
				
		pagerItems.removeClass('active');
		pagerItems.eq(newPagerIndex).addClass('active');
		
		$('#details .pageOverview .currentPageNumber').html(newPagerIndex);
		
		contentItems.hide();
		contentItems.eq(newPagerIndex - 1).show();
		
	});
	
	
	
	
	
	// home page javascript settings -------------------
	
	// configure carousels
	$('.carouselHome ul').cycle({ 
	  timeout: 4650, // ms btw transitions (0 to disable auto advance)
	  speed: 850, // speed of transition --> gesamt 5.5sec
	  prev: '.carouselNavi .prev', 
	  next: '.carouselNavi .next',
	  pager: '.carouselNavi .navi',
	  pause: 1, // true to enable "pause on hover" 
	  sync: 1 // true if in/out transitions should occur simultaneously
	});

	if ( $('.carouselHome ul').children().size() < 2 ) {
		$('.carouselNavi').hide();
	}
	
});
//--- end of document.ready.function ----------------


// labeled Inputs 
// a lable inside the input is displayed & hidden onSelect
function labeledInputs() {
  $(".search input[type='text']").focus(function () {
    $(this).addClass("focus");
    if (this.value == this.defaultValue){this.value = '';}
    if(this.value != this.defaultValue){this.select();}
  }).blur(function () {
    if ($.trim(this.value) == ''){
      $(this).removeClass("focus");
      $(this).removeClass("filled");
      this.value = (this.defaultValue ? this.defaultValue : '');
    } 
    else {$(this).removeClass("focus").addClass("filled");}
  });
 }

// openDetail for product page
function openDetail() {
	
	$('#details').show();
	$('#details').prepend('<img class="shadow" src="/media/layout/img/bg_shadow~2.png" alt="" />');
		
//  $('#caption').hide();
//	var mainHeight = $('#main').height();
//	var detailsWidth = $('#details').width();
//	var detailsHeight = $('#details').height();
//	$('#details .content').height(detailsHeight);
//	$('.shadow').height(detailsHeight+65).width(detailsWidth+5);

	resetDetailPager();
}


function resetDetailPager() {
	var pagerItems = $('#details .pager a');
	var contentItems = $('#details').find('.content');
	
	var newPagerIndex = 1;
	
	pagerItems.removeClass('active');
	pagerItems.eq(newPagerIndex).addClass('active');
	
	$('#details .pageOverview .currentPageNumber').html(newPagerIndex);
	
	contentItems.hide();
	contentItems.eq(newPagerIndex - 1).show();
}





