$(document).ready(function(){

		if ($('#hintGallery').length > 0)
		hintGallery("hintGallery");

		$('div.listPerson').hover(function() {
		
			elementId = "#" + $(this).attr("id") + " img.personThumb";
			
			normalThumb = "images/faces/" + $(this).attr("id") + "_default.jpg";
			hoverThumb = "images/faces/" + $(this).attr("id") + "_hover.jpg"
		
			$(elementId).attr("src", hoverThumb);
		}, function() {
			$(elementId).attr("src", normalThumb);
		});
		
		
		$(".newsticker-jcarousellite").jCarouselLite({  
				 vertical: true,  
				 visible: 2,  
				 auto: 4000,  
				 speed: 1000 
		});  


		if ($(".caseSelect").length > 0) {
			$(".caseSelect").change(function(){
				if ($(this).val() != "")
				window.location.href = $(this).val();
			});
		}
		
		

		if ($('#imgs').length > 0)
		$('#imgs').cycle({
			fx:      'scrollLeft',
			next:   '#right',
			timeout:  6000
		});
		
	
		
	//select all the a tag with name equal to modal
	$('a[name=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
		
		//Get the A tag
		var id = $(this).attr('href');
	
		//Get the screen height and width
		var maskHeight = $(window).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight,'position':'fixed','top':0,'left':0});
		
		//transition effect		
		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow", 0.8);	

		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		//Set the popup window to center
		$(id).css('position', 'fixed');

		$(id).css('top',  $('#mask').height()/2-$(id).height()/2);
		$(id).css('left', $('#mask').width()/2-$(id).width()/2);
	

		
		//transition effect
		$(id).fadeIn(2000); 
	
	});
	
	//if close button is clicked
	$('.windowSmall .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		$('#mask').hide();
		$('.windowSmall').hide();
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.windowSmall').hide();
	});			
	
	$('.windowLarge .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		$('#mask').hide();
		$('.windowLarge').hide();
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.windowLarge').hide();
	});		
		

  });








	function hintGallery(container) {
		
		jQuery.fn.isChildOfElement = function(b){
			return (this.parents(b).length > 0);
		};

		$('#' + container + ' .hintDiv').each(function(index){
			$(this).attr("id", container+"Div_" + (index+1));
			$("#" + container + "Div_" + (index+1) + " *").attr("rel", container+"Div_" + (index+1));
		});
		
		$('#' + container + ' img').each(function(index){
			$(this).attr("rel", container+"Div_" + (index+1));
			$(this).addClass("hintImg");
			$("#"+container+"Div_" + (index+1) + " div.image").html("<img alt=\"" + $(this).attr("alt") + "\" src=\"" + $(this).attr("src") + "\" />");
		});
		

		$(document).mouseover(function(event){

				if ($(event.target).isChildOfElement('#'+container) == false) {
					$('.hintDiv').fadeOut("4000");
				} 
				
				else if ($(event.target).hasClass('hintImg')) {

					var imgOffset = $(event.target).offset();

					$("#" + $(event.target).attr("rel")).css("top", (imgOffset.top - 20) + "px");
	
					if ($("#" + $(event.target).attr("rel")).hasClass("alignLeft")) {
						$("#" + $(event.target).attr("rel")).css("left", (imgOffset.left - ($("#" + $(event.target).attr("rel")).outerWidth() / 2) - 20) + "px");
						
					} else {
						$("#" + $(event.target).attr("rel")).css("left", (imgOffset.left - 20) + "px");
					}

					if ($("#" + $(event.target).attr("rel")).css("display") != "block") {

						$('.hintDiv[id!="' + $(event.target).attr("rel") + '"]').fadeOut("4000");
						$("#" + $(event.target).attr("rel")).fadeIn("2000");

					}
					
				}

		});
		
	}
	
	
	
	
	
	
	

		//accordion 
	
	$(function () {
			
			$('ul.drawers').accordion({
			
			// the drawer handle
			header: 'h5.drawer-handle',
			active: '.open',
			alwaysOpen: false,
			
			// our selected class
			selectedClass: 'open',
			fillSpace: false,
			autoHeight: false,
			// match the Apple slide out effect
			event: 'click'  });
			
		});


		$(function () {
			
			$('ul.drawers-child').accordion({
			
			// the drawer handle
			header: 'h5.drawer-child-handle',
			active: '.open',
			alwaysOpen: false,
			
			// our selected class
			selectedClass: 'open',
			fillSpace: false,
			autoHeight: false,
			// match the Apple slide out effect
			event: 'click'  });
			
		});	
		
		
		
		$(function () {
			
			$('ul.downloadDrawer').accordion({
			
			// the drawer handle
			header: 'a.drawer-handle',
			active: '.open',
			alwaysOpen: false,
			
			// our selected class
			selectedClass: 'open',
			fillSpace: false,
			autoHeight: false,
			// match the Apple slide out effect
			event: 'click'  });
			
		});


$(document).ready( function (){
	
	$(".zoom").click( function(){
		
		
		var img = $(this).parent().find('div.imgholder');
		var imgzoom = $(this).parent().find('div.imgholder_zoom');

		if($(img).css('display') == 'block'){
			$(img).css('display', 'none');
			$(imgzoom).css('display', 'block');
			$(this).html('Zoom -');
		}else{
			$(img).css('display', 'block');
			$(imgzoom).css('display', 'none');
			$(this).html('Zoom +');
		}

	});

	$(".imgholder_zoom").mousemove( function(e){
		//position of the mouse inside the element
		var x = e.pageX - $(this).position().left;
		var y = e.pageY - $(this).position().top;

		//percentage of the mouse to the element
		var pw = (x / $(this).width()) * 100;
		var ph = (y / $(this).height()) * 100;

		//width and heigh of the image
		var img = $(this).find('img');
		var iw = $(img).width();
		var ih = $(img).height();

		//get the overflow of the image
		var ow = iw - $(this).width();
		var oh = ih - $(this).height();

		var movew = (ow / 100) * pw;
		var moveh = (oh / 100) * ph;

		$(img).css({
			'left' : '-'+Math.floor(movew)+'px',
			'top'  : '-'+Math.floor(moveh)+'px',
			position : 'absolute'
		});
	});

});
	
	
	
	
	
	
