(function($){

Site.init = function(){
	/**
	 * News
	 */
	$('#home_noticias').accordion({
		header: 'h3',
		selectedClass: 'active',
		event: 'mouseover'
	});
	
	/**
	 * Contact jump
	 */
	$('#contact a').click(function(){
		var $li = $(this).parent();
		
		if(!$li.is(':animated')){
			$li.animate({ top: '-=5' }, 200, function(){
				$(this).animate({ top: '+=5' }, 200, function(){
					$(this).animate({ top: '-=5' }, 200, function(){
						$(this).animate({ top: '+=5' }, 200, function(){
							$(this).animate({ top: '-=5' }, 200, function(){
								$(this).animate({ top: '+=5' }, 200, function(){
								});
							});
						});
					})
				});
			});
		}
		
		if($li.attr('id') == 'email')
			window.open(this.href, 'ipb_'+$li.attr('id'), 'height=250,width=250');
		
		return false;
	});
	
	/**
	 * Cast: Use Coda popup bubbles, mostly copy and pasted, too lazy to write a new one.
	 * @url http://jqueryfordesigners.com/coda-popup-bubbles/
	 *
	$('#cast li').each(function () {
		// options
		var distance = 10;
		var time = 150;
		var hideDelay = 300;

		var hideDelayTimer = null;

		// tracker
		var beingShown = false;
		var shown = false;

		var trigger = $('a', this).attr('target', '_blank');
		var popup = $('span', this).css('opacity', 0);

		// set the mouseover and mouseout on both element
		$(trigger.get(0)).bind('mouseenter', function () {
			// stops the hide event if we move from the trigger to the popup element
			if (hideDelayTimer) clearTimeout(hideDelayTimer);

			// don't trigger the animation again if we're being shown, or already visible
			if (beingShown || shown) {
				return;
			} else {
				beingShown = true;

				// reset position of popup box
				popup.css({
					top: -20,
					//left: '50%',
					display: 'block', // brings the popup back in to view
					zIndex: 3
				})

				// (we're using chaining on the popup) now animate it's opacity and position
				.animate({
					top: '-=' + distance + 'px',
					opacity: 0.75
				}, time, 'swing', function() {
					// once the animation is complete, set the tracker variables
					beingShown = false;
					shown = true;
				});
			}
		}).bind('mouseleave', function () {
			// reset z-index
			popup.css('zIndex', 1);
			
			// reset the timer if we get fired again - avoids double animations
			if (hideDelayTimer) clearTimeout(hideDelayTimer);

			// store the timer so that it can be cleared in the mouseover if required
			hideDelayTimer = setTimeout(function () {
				hideDelayTimer = null;
				popup.animate({
					top: '-=' + distance + 'px',
					opacity: 0
				}, time, 'swing', function () {
					// once the animate is complete, set the tracker variables
					shown = false;
					// hide the popup entirely after the effect (opacity alone doesn't do the job)
					popup.css('display', 'none');
				});
			}, hideDelay);
		});
	});
	/**/
	
	
	/**
	 * Use jQuery Flash to embbed the solutions and logo on the site.
	 * @url http://www.jquery.lukelutman.com/plugins/flash/
	 */
	$('#flash-logo:eq(0)').flash({
		src: Site.info.url + 'uploads/media/logo.swf',
		width: 81,
		height: 69,
		wmode: 'transparent',
		flashvars: { indexURL: Site.info.url }
	});
	
	$('#anim:eq(0)').flash({
		src: Site.info.url + 'uploads/media/anim.swf',
		width: 840,
		height: 202,
		bgcolor: '#FFFFFF',
		flashvars: { xmlSrc: Site.info.url + 'xml/soluciones' }
	});
	
	var $solutionAnim = $('#solution_anim');
	if($solutionAnim.length > 0){
		var data = $solutionAnim.metadata();
		
		$solutionAnim.flash({
			src: Site.info.url + 'uploads/media/anim.swf',
			width: 840,
			height: 202,
			bgcolor: '#FFFFFF',
			flashvars: { xmlSrc: Site.info.url + 'xml/soluciones?singleid=' + data.flash }
		});
	}
	
	/**
	 * Body Class, switch between widescreen and normal design
	 */
	if($(window).height() > 680){
		$(document.body).removeClass();
	}
}

})(jQuery);