$(document).ready(function()
{
	//-------------------- Home page news slider
	$('ul.news-list').cycle(
	{ 
		fx:      'fade', 
		speed:    600, 
		timeout:  4000 
	});
	
	($('.module').length) ? '' : $('#main_content').width(650);
	
});
 
 
 
 
 $(document).ready(function(){
	
	$(".flashPlay").click( function() {
			$('.flashBox').css({'left':Math.floor($(this).offset().left), 'top':Math.floor($(this).offset().top)});
			$('.screen').css({ "display": "block", opacity: 0.7, "width":$(document).width(),"height":$(document).height()});
			$('.flashBox').css({"display": "block"}).animate({'width':'920', 'height':'484', 'left':'50%', 'top':'50%'}, 750, function() {
					swfobject.embedSWF("assets/flash/bsr_processes.swf", "fObj", "1030", "543", "9.0.0", '', {}, {'wmode':'transparent'});
				}
			);
		}
	);
	
	$(".flashClose").click( function() {
			//console.log("flashed!");
			$("#fObj").remove();
			$('.flashBox').prepend("<div id='fObj'></div>");
			$('.flashBox').animate({'width':'0', 'height':'0', 'left':'0', 'top':'0'});
			$('.flashBox').css("display", "none");
			$('.screen').css("display", "none");
		}
	);	
 
 	/*------------------- Galeries ------------------------------------------------------------------------*/
	//----------- Main Slideshow
	
	$('#slideshow').cycle({ 
		fx:     'fade', 
		speed:   2500, 
		timeout: 5000, 
		next:   '#next',
        prev:   '#prev',
		before:  onBefore, 
		after:   onAfter,
		cleartype:  1
	 });
	
	function onBefore() { 
		$('#output').animate({  
			height: "0"
		}, 500 );
		$('#output').html("");
	}
	
	function onAfter(curr,next,opts) { 
		if (this.alt != '') {
			$('#output').animate({ 
				height: "36px"
			}, 800 );
			//console.log(opts.slideCount);
			$('#output').append('<p>' + this.alt + '</p>'); 

		}
		if (opts.slideCount==1) {
			$('#slideshow').cycle('stop');
			return false;
		}
	}
	
	$('#pause').click(function() { $('#slideshow').cycle('pause'); return false; });
    $('#play').click(function() { $('#slideshow').cycle('resume'); return false; });

	/*-----------------------------------------------------------------------------------------*/
	/*-----------------------------------------------------------------------------------------*/
	$.easing.custom = function (x, t, b, c, d) { 
		var s = 1.70158;  
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; 
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; 
	}
	$.easing.easeOutExpo = function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	};
	$.easing.easeOutBounce = function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	};
	
	$("#mainNav ul").lavaLamp({
		fx: "custom",
		speed: 700
	});
	
	//--------------------------------- Sub Menu
	$('#subMenu ul li ul').hide();
	$('#subMenu ul li.active ul').show();

	$('#subMenu ul li:has(ul)').hoverIntent(function(){
		var target = $(this);
		target.addClass('active').find('ul').slideDown();
		$('#subMenu ul li:has(li)').not(target).removeClass('active').find('ul').slideUp();
		return true;
	}, function() {});

	//Home content slider
	$("#flowpanes").scrollable({
		size: 1,
		clickable: false,
		easing:	'custom',
		speed: 1000
	}).mousewheel(1000).navigator({ 
        navi: "#flowtabs", 
        naviItem: 'a', 
        activeClass: 'active'
    })

	$('.box:last').css({
		'margin-right': '0',
		'border': 'none'
		
	});
	$('table tr:first td').css('padding-top','0');

}); //Close document.ready

$(window).bind("load", function() {							
    //-----------  Preload images for 
	$('#loading').hide();
	$('#slideshowWrapper').fadeIn('slow');
	$('#flowpanes,#flowtabs').fadeIn('slow');

});
