

	$(function(){

		
		$('a[href$=careers.html]').click(function(){
		
			var src = $(this).attr('href');
			
			var $iframe = $('<iframe/>').attr({
				src: src,
				width: '100%',
				height: '100%',
				frameBorder: 0
			});
			
			$('#careersdiv').remove();
			
			var careersdiv = $('<div></div>').attr({
				id: 'careersdiv'
				//title: 'Careers'
			}).html($iframe);
			
			//$iframe.append(careersdiv);
			
			
			
			$('body').append(careersdiv);
			
			$('#careersdiv').dialog({
				width: 665,
				height: 450,
				bgiframe: true,
				modal: true,
				zIndex: 3000
			});
			
			return false;
		});

	/*
	#################################
	INIT FUNCTIONS
	#################################
	*/
		var scrollerSpeed = 3000;
		
		setTimeout(function(){
			fadePanel($('.homeimages .panel:first'));
			fadePanel($('.subimages .panel:first'));
		},scrollerSpeed);
		
		function fadePanel(e)
		{
			var $e = $(e);
			$e.css({
				position: 'absolute',
				zIndex: 1000
			}).show();
			
			var next = $e.next('.panel');
			if (!$(next).length) {
				next = $e.siblings('.panel:first');
			}
			$(next).hide().css({
				position: 'absolute',
				zIndex: 1100
			}).fadeIn('slow',function(){
				setTimeout(function(){
					fadePanel(next);
				},scrollerSpeed);
				$(e).hide();
			});
		}
		
		/*
			HELP:
			
			btnPrev    : previous button. Can be set outside ot the carousel with $('#layerId') for example.
			btnNext    : next button. Can be set as above
			mouseWheel : mouseWheel activation or not. true or false.
			auto       : whether the carousel must scroll automatically, without arrows. true or false.
			speed      : speed of the animation. value in ms.
			easing     : animation effect. relative to jquery framework.
			vertical   : whether the carousel is displayed horizontally or vertically. true or false.
			circular   : whether the animation must scroll in a cicular way, without stopping. true or false.
			visible    : size of the carousel. 
				'4' would indicate to display 4 elements
				'100px' would indicate to display 100 pixels only
				'100%' would indicate to display the carousel with a 100% width.
			start      : which position in pixels the carousel will start at.
			step       : the step of the animation. value in pixels
			eltByElt   : shall the carousel move element by element, or in a linear way ? true or false.
			evtStart   : event customization : start event. 'mouseover', 'click', etc..
			evtStop    : event customization : stop event. 'mouseout', 'mouseup', etc...
		*/
		
		$(".homesector").jMyCarousel({  
			visible: '100%',  
			eltByElt: false,
			mouseWheel: true,
			speed: 200,
			btnNext: $('.nextbutton'),
			btnPrev: $('.prevbutton')
		}).mouseover(function(){
			$(this).children('ul:first').stop();
			$(this).addClass('hover');
			
		}).mouseout(function(){
			$(this).removeClass('hover');
		});
		
		$(".homesector img").mouseover(function(){
			var src = $(this).attr('src');
			src = src.replace('.jpg','_on.jpg');
			src = src.replace('.gif','_on.gif');
			src = src.replace('.png','_on.png');
			$(this).attr('src',src);
		}).mouseout(function(){
			var src = $(this).attr('src');
			src = src.replace('_on.jpg','.jpg');
			src = src.replace('_on.gif','.gif');
			src = src.replace('_on.png','.png');
			$(this).attr('src',src);
		});
		
	});
	
	$(window).load(function(){
	
	/*
	#################################
	SCROLLER FUNCTIONS
	#################################
	*/
	

		
		scrollStart($( "ul:eq(0)" , $(".homesector") ),{
			speed: 6000
		})
		
		window.setInterval(function(){
			if (!$(".homesector ul:animated").length && !$(".homesector").hasClass('hover')) {
				scrollStart($( "ul:eq(0)" , $(".homesector") ),{
					speed: 6000
				})
			}
			
		},100);
	});
	
	/*
	#################################
	HELPER FUNCTIONS
	#################################
	*/
	
	function scrollStart ( $scroll , opt ) {
	
		var pos = -( $scroll.children( ":eq(0)" ).width() );
		var spd = opt.speed - ( Math.abs ( parseInt( $scroll.css( "marginLeft" ) ) ) * ( opt.speed / $scroll.children( ":eq(0)" ).width() ) );
		
		$scroll.animate(
			{
				  marginLeft: ( pos || "0" ) + "px"
				, marginTop: (0) + "px"
			}
			, spd
			, "linear"
			, function () {
				$scroll.append( $scroll.children( ":eq(0)" ) );
				$scroll.css( "marginLeft" , "0px" );
				if (!$scroll.parents('div:first').hasClass('hover')) {
					scrollStart( $scroll , opt );
				}
			}
		);
	};

