var TIME = 400;
var circle_id = '';
var circle = Array();
var step = 0;
var rotateStep = 0;
var overed = false;
circle['sTrash'] = Array();
circle['sTrash']['w'] = circle['sTrash']['h'] = 209;
circle['sApp'] = Array();
circle['sApp']['w'] = circle['sApp']['h'] = 209;
circle['sUnibin'] = Array();
circle['sUnibin']['w'] = circle['sUnibin']['h'] = 190;
circle['sLogs'] = Array();
circle['sLogs']['w'] = circle['sLogs']['h'] = 209;
circle['sCashes'] = Array();
circle['sCashes']['w'] = circle['sCashes']['h'] = 209;
circle['sJunk'] = Array();
circle['sJunk']['w'] = circle['sJunk']['h'] = 227;
circle['sLanguage'] = Array();
circle['sLanguage']['w'] = circle['sLanguage']['h'] = 209;
circle['sExtensions'] = Array();
circle['sExtensions']['w'] = circle['sExtensions']['h'] = 227;
var icon = ['#sApp', '#sCashes', '#sLogs', '#sLanguage', '#sTrash', '#sJunk', '#sUnibin', '#sExtensions', '.icon'];
var rotate = ['5','10','5','0','-5','-10','-5','0','5','10','5','0','-5','-10','-5','0'];

$(document).ready(function(){
	resize();
	overIcon();
	setTimeout('randomRotate()',2000);
	
	$(".monitor").mouseover(function(){
		$('.download').stop().animate({'opacity':'1'},TIME/4);
	}).mouseout(function(){
		$('.download').stop().animate({'opacity':'0'},TIME/4);
	});
	
	$(".review > div").click(function(){
		showReview(this.className);
	});
	
	$(".buttons > div").click(function(){
		showReview(this.id);
	});
	
	$(".gray_bg").click(function(){
		hidePopup();
	});
});


$(window).resize(function(){
	resize();
});

function resize(){
	$(".gray_bg").css({'height':$(document).height() + 'px'});
}

function updateOrientation(){
	resize();
}

function hidePopup(id){
	$(".gray_bg").fadeOut(TIME/4);
	$("#popup").fadeOut(TIME/4);
	overed = false;
}

function showPopup(){
	overed = true;
	$(".gray_bg").fadeIn(TIME/4);
	$("#popup").fadeIn(TIME/2);
}

function showReview(id){
	if ($('.gray_bg').css('display') == 'none'){
		showPopup();
	}
	$(".buttons > div").removeClass('on');
	$("#"+id).addClass('on');
	$(".txt_review > div").hide();
	$('.txt_'+id).show();
}

function overIcon(){
	$(".icon").mouseover(function(){
		overed = true;
		circle_id = this.id;
		$("." + circle_id).css({'z-index':'1000'});
		$("#" + circle_id + " > .icon_on").stop().animate({'opacity':'1'},TIME/2);
		$("." + circle_id + " > .circle").css({
				'width':'0', 
				'height':'0',
				'left':((circle[circle_id]['w']/2).toFixed(0)) + 'px',
				'margin-top':'50px',
				'top':'0'});
		$("." + circle_id + " > .circle").stop().animate({
				'opacity':'1',
				'width':(circle[circle_id]['w'] + 10) +'px', 
				'height':(circle[circle_id]['h'] + 10) +'px',
				'left':'-5px',
				'top':'-55px'},TIME/2);
		
		setTimeout(function(){
			if (overed){
				$("." + circle_id + " > .circle").stop().animate({
					'opacity':'1',
					'width':circle[circle_id]['w'] +'px', 
					'height':circle[circle_id]['h'] +'px',
					'left':'0',
					'top':'-50px'},TIME/4);
			}
		},TIME/2);
		$("." + circle_id + " > p").stop().animate({'opacity':'1'},TIME);
		
	}).mouseout(function(){
		overed = false;
		$('.' + circle_id).css({'z-index':'10'})
		$("#" + circle_id + " > .icon_on").stop().animate({'opacity':'0'},TIME/2);
		$("." + circle_id + " > .circle").stop().animate({
				'opacity':'0',
				'width':'0', 
				'height':'0',
				'left':((circle[circle_id]['w']/2).toFixed(0)) + 'px',
				'top':'0'},TIME/2);
		$("." + circle_id + " > p").stop().animate({'opacity':'0'},TIME/2);
	});
}

function randomRotate(){
	rotateStep = 0;
	obj = icon[step];
	if (!overed){
		step = (step == 8) ? 0 : step + 1;
	}
	turbineRotate(obj);
	setTimeout('randomRotate()', (1000 + Math.random() * 1000));
}

function rotateObject(obj, rotateStep){
	deg = rotate[rotateStep];
	$(obj).css({"-webkit-transform": "rotate(" + deg + "deg)","-moz-transform": "rotate(" + deg + "deg)"});
	if (rotate[rotateStep+1] != null && !overed){
		setTimeout(function(){
			rotateObject(obj, rotateStep+1);
		},30);
	} else {
		setTimeout(function(){
			$(obj).css({"-webkit-transform": "rotate(0deg)","-moz-transform": "rotate(0deg)"});
		},30);
	}
}


function turbineRotate(obj) {
	if (!overed){
		rotateObject(obj, 0);
	}
}     






