// JavaScript holzbau-foidl.at ... copyright 2011


// init important javascript functions for frontend
$(document).ready(function() {
	initialize_referenz_menu();
	initialize_primary_menu();
	initialize_projectslide();
	initialize_projectslideipad();
	initialize_projectslidetv();
	initialize_photoslide();
	initialize_project_sidebar();
	initialize_project_sidebar_ipad();
});

// User Agent (Browserkennung) auf einen bestimmten Browsertyp prüfen */  
function checkBrowserName(name){  
var agent = navigator.userAgent.toLowerCase();  
if (agent.indexOf(name.toLowerCase())>-1) {  
  return true;  
}  
return false;  
}

// initialize Primary Menu Mouseover
function initialize_primary_menu() {

$("#primaryMenu .expanded:not(.active-trail) ul").each(function() {$(this).css("marginLeft",-$(this).width()-10); });

	$("#primaryMenu .expanded:not(.active-trail)").hover(
	  function () {
	    $(this).children('ul').animate({"marginLeft": "0px"}, "slow");
		$("#primaryMenu .expanded:not(.first)").not(this).fadeOut('quick');
		
		
	  },
	  function () {
	    $(this).children('ul').animate({"marginLeft": -$(this).width()}, "slow");
		$("#primaryMenu .expanded:not(.first)").not(this).fadeIn('quick');
	  }
	);
}

// initialize Referenz Menu Mouseover
function initialize_referenz_menu() {
	
	if(checkBrowserName('ie')){ //IE Hack
		$('#referenceMenu .expanded ul').backOpacity({
			background: '#004c82',
			opacity: '0.8'
		});
		$('#referenceMenu .expanded div').css("display","none");
	}
	
	$("#referenceMenu .expanded:not(.active-trail)").hover(
	  function () {
		if(checkBrowserName('ie')){$(this).children('div').fadeIn('quick');} //IE Hack
	    $(this).children('ul').fadeIn('quick');
	  },
	  function () {
		if(checkBrowserName('ie')){$(this).children('div').fadeOut('quick');} //IE Hack
	    $(this).children('ul').fadeOut('quick');
	  }
	);
}

// initialize_project_slider

var easySl = false;

function initialize_projectslide() {
	
	$("#play_prev").css( {backgroundPosition: '0 23px', cursor: 'default'} );
	
	$("#projectSlide").easySlider({
			prevText:'',
			nextText:'',
			nextId:'play_next2',
			prevId:'play_prev2',
			orientation:'horizontal',
			auto: true,
			continuous: false,
			speed: 600,
			pause: 3500
	});
	// make h2 opacity
	$('.topstorycontainer h2').each(function(index) {
		//window.alert($(this));
		$(this).fadeTo(0, 0.8);
	});
}

// initialize_project_slider iPad

var easySl = false;

function initialize_projectslideipad() {
	
	$("#play_prev").css( {backgroundPosition: '0 23px', cursor: 'default'} );
	
	$("#projectSlideIpad").easySlider({
			prevText:'',
			nextText:'',
			nextId:'play_next2',
			prevId:'play_prev2',
			orientation:'horizontal',
			auto: false,
			continuous: false,
			speed: 600,
			pause: 3500
	});
	// make h2 opacity
	$('.topstorycontainer h2').each(function(index) {
		//window.alert($(this));
		$(this).fadeTo(0, 0.8);
	});
	
}

// initialize_project_slider Tv

var easySl = false;

function initialize_projectslidetv() {
	
	$("#play_prev").css( {backgroundPosition: '0 23px', cursor: 'default'} );
	
	$("#projectSlideTv").easySlider({
			prevText:'',
			nextText:'',
			nextId:'play_next2',
			prevId:'play_prev2',
			orientation:'horizontal',
			auto: false,
			continuous: false,
			speed: 600,
			pause: 3500
	});
	// make h2 opacity
	$('.topstorycontainer h2').each(function(index) {
		//window.alert($(this));
		$(this).fadeTo(0, 0.8);
	});
}

// initialize_photo_slider

var easySl = false;

function initialize_photoslide() {
	$("#photoSlide, #photoSlide_right").easySlider({
			prevText:'',
			nextText:'',
			nextId:'play_next2',
			prevId:'play_prev2',
			orientation:'horizontal',
			auto: true,
			continuous: false,
			speed: 900,
			pause: 12000
	});
	// make h2 opacity
	$('.topstorycontainer h2').each(function(index) {
		//window.alert($(this));
		$(this).fadeTo(0, 0.8);
	});
}

// initialize_project_sidebar
function initialize_project_sidebar() {

	$("#projectSlide .sidebarOpen, #projectSlide  .linkTitlePic").click(
	  function () {
		if($(this).parent('div').hasClass('opened')) {
	    	$(this).parent('div').animate({"right": "-167px"}, "quick");
			$(this).parent('div').removeClass('opened');
			$(this).css("background", " url(/sites/all/themes/foidl/layout/sidebar_link_bg_more.png) 570px 424px no-repeat");
		}
		else {
			$(this).parent('div').animate({"right": "0px"}, "quick");
			$(this).parent('div').addClass('opened');
			$(this).css("background", " url(/sites/all/themes/foidl/layout/sidebar_link_bg_less.png) 570px 424px no-repeat");
		}
	  }
	);
}

// initialize_project_sidebar
function initialize_project_sidebar_ipad() {

	$("#projectSlideIpad .sidebarOpen, #projectSlideIpad  .linkTitlePic").click(
	  function () {
		if($(this).parent('div').hasClass('opened')) {
	    	$(this).parent('div').animate({"right": "-305px"}, "quick");
			$(this).parent('div').removeClass('opened');
			$(this).css("background", " url(/sites/all/themes/foidl/layout/sidebar_link_bg_more.png) no-repeat scroll right bottom transparent");
		}
		else {
			$(this).parent('div').animate({"right": "0px"}, "quick");
			$(this).parent('div').addClass('opened');
			$(this).css("background", " url(/sites/all/themes/foidl/layout/sidebar_link_bg_less.png) no-repeat scroll right bottom transparent");
		}
	  }
	);
	
	/*$("#projectSlideIpad .sidebarOpen, #projectSlideIpad .linkTitlePic").click(
	  function () {
		if($(this).parent('div').hasClass('opened')) {
	    	$(this).parent('div').css({'-webkit-transform': 'translate3d(0, 0, 0)'});
			$(this).parent('div').removeClass('opened');
		}
		else {
			$(this).parent('div').css({'-webkit-transform': 'translate3d(-167px, 0, 0)'});
			$(this).parent('div').addClass('opened');
		}
	  }
	);*/
}





//css({'-webkit-transform': 'translate3d(167px, 0, 0)'});
