var now = false;
function moveCircles(){
	now = true;

	var bezier_params1 = {
	    start: { x: 64, y: 120, angle: 1*20, length: 0 },  
	    end: { x:446, y:-144, angle: 1*20, length: 0 }
	  }
	var bezier_params2 = {
	    start: { x: -302, y: -24, angle: 2*-20, length: 0},  
	    end: { x:270, y:-246, angle: 2*-20, length: 0 }
	  }
	var bezier_params3 = {
	    start: { 
	      x: 234, y: -286, angle: 3*20, length: 0},  
	    end: { x:280, y:-220, angle: 3*20, length: 0 }
	  }
	var bezier_params4 = {
	    start: { x: 720, y: 140, angle: 4*-20, length: 0 },  
	    end: { x:610, y:30, angle: 4*-20, length: 0 }
	  }
	  
	$("#green").animate({path : new $.path.bezier(bezier_params1)}, 21000);
	$("#cyan").animate({path : new $.path.bezier(bezier_params2)}, 21000);
	$("#yellow").animate({path : new $.path.bezier(bezier_params3)}, 21000);
	$("#orange").animate({path : new $.path.bezier(bezier_params4)}, 21000, function(){
		now = false;
	});
	return false;
}

function gt(obj, deg){
	deg2radians = Math.PI * 2 / 360;
    rad = deg * deg2radians ;
    costheta = Math.cos(rad);
    sintheta = Math.sin(rad);
	if (obj == 11){
		return costheta;
	} else if (obj == 12){
		return -sintheta;
	} else if (obj == 21){
		return sintheta;
	} else if (obj == 22){
		return costheta;
	}
}

$(document).ready(function(){

	// start slideshow
	$('#cr-slide-container').fadeIn(500, function(){
		$('.cr-slide1').fadeIn(1000, function(){
			setTimeout(function(){
				$('.bottom-box').animate({bottom:0}, 1000, 'swing');
			},2000);
		});
	});

	// begin circle animations in header
	moveCircles(); 
	
	// logic for spinning nav animations
	var ua = $.browser;
	var num = parseFloat(ua.version);
	var deg = new Array();
	for (i=0;i<5;i++){
		deg[i] = 0;
	}
	var cw = new Array();
	var ccw = new Array();

	if (ua.mozilla){
		cs = '-moz-transform';
	} else if (ua.opera){
		cs = '-o-transform';
	} else if (ua.webkit || ua.safari){
		cs = '-webkit-transform';
	} else if (ua.msie && num >= 9){
		cs = 'msTransform';
	} else if (ua.msie && !$.support.opacity){
		cs = 'filter';
		if (num >5 && num <7){
			$('body').addClass('ie6');
		}
	} else {
		cs = 'transform';
	}
	
	$('.symbol').each(function(ind){
		var i = ind+1;
		$(this).hover(function(){
			var $this = $('#symbol'+i);
			if ($.support.opacity) {
				$($this).stop().animate({'opacity':1 }, 2400, 'linear');
				$(this).find('span.text').stop().animate({'opacity':1 }, 2400, 'linear');
				cw[i] = setInterval(function () {
					deg[i] = (deg[i] >= 360 ? 360 : deg[i]+30);	
					$($this).css(cs,'rotate('+deg[i]+'deg)');
				}, 100);
				clearInterval(ccw[i]);
			} else {
				$this.css('filter','alpha(opacity=100)');
			}
		}, function(el){
			var $this = $('#symbol'+i),
				op = ($this.attr('id') == 'symbol0' ? 40 : 20);
			if ($.support.opacity) {
				$($this).stop().animate({'opacity':op/100 }, 2400, 'linear');
				$(this).find('span.text').stop().animate({'opacity':op/100 }, 2400, 'linear');
				ccw[i] = setInterval(function () {
					deg[i] = (deg[i] <= 0 ? 0 : deg[i]-30);
					$($this).css(cs,'rotate('+deg[i]+'deg)');
				}, 100);
				clearInterval(cw[i]);
			} else {
				$this.css('filter','alpha(opacity='+op+')');
			}
		});
	});
	
	$('#cover').click(function(){
		if (!now) moveCircles();
		return false;
	});
	
});

