var flashvars 	= { gotourl: global_url + 'finaleparty' };
var params 		= { wmode: 'transparent' };
swfobject.embedSWF(global_url + 'image/SignupButton.swf', 'signup_flash', '129', '129', '9.0.124', global_url + 'image/expressInstall.swf', flashvars, params, false);

$(document).ready(function(){
	$('.coords .system')
		.mousemove(function(event){
			var score = coord.getScore(event);
			
			var minfontsize = 6;
			var maxfontsize = 14;
			var fontdiff = maxfontsize-minfontsize;
			var fontsize = {
				x1: (minfontsize + (score.param1 * -1 * fontdiff / 2) + fontdiff / 2),
				x2: (minfontsize + (score.param1 * fontdiff / 2) + fontdiff / 2),
				y1: (minfontsize + (score.param2 * -1 * fontdiff / 2) + fontdiff / 2),
				y2: (minfontsize + (score.param2 * fontdiff / 2) + fontdiff / 2)
			}
			
			$(this).find('.x-axis-1').css('font-size', fontsize.x1);
			$(this).find('.x-axis-2').css('font-size', fontsize.x2);
			$(this).find('.y-axis-1').css('font-size', fontsize.y1);
			$(this).find('.y-axis-2').css('font-size', fontsize.y2);
		})
		.click(function(event){
			var score = coord.getScore(event);
			
			var form = $('.coords form');
			form.find('input[name="param1_score"]').val(score.param1);
			form.find('input[name="param2_score"]').val(score.param2);
			form.submit();
		});
	
	$('#search input[name="criteria"]')
		.focus(function(){ if (this.value == this.title) this.value = ''; })
		.blur(function(){ if (!this.value) this.value = this.title; });

	$('form#search .submit').click(function(){
		$('form#search').submit();
	});

	$('.box .body .content .signup')
		.mouseover(function(){
			$(this).addClass('signup_hover');
		})
		.mouseout(function(){
			$(this).removeClass('signup_hover');
		});
	
	/*
	var signup_hover = new Image();
	signup_hover.src = global_url + 'image/btn.signup.hover.png';
	var signup = new Image();
	signup.src = global_url + 'image/btn.signup.png';
	
	$('#content .signup')
		.mouseover(function(){
			if ($.browser.msie && /^6/.test($.browser.version))
			{
				$(this).css('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + signup_hover.src + '", sizingMethod="crop");');
			}
			else
			{
				$(this).css('background-image', 'url(' + signup_hover.src + ')');
			}
		})
		.mouseout(function(){
			if ($.browser.msie && /^6/.test($.browser.version))
			{
				$(this).css('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + signup.src + '", sizingMethod="crop");');
			}
			else
			{
				$(this).css('background-image', 'url(' + signup.src + ')');
			}
		})
		.click(function(){
			login.show(false, null, { referer: 'signup_button' });
		});
	*/
	//roller.prepare();
});

var coord = {
	getScore: function(event){
		var offset = $('.coords .system').offset()
		var dim = {
			width: ($('.coords .system').width()-20),
			height: ($('.coords .system').height()-20)
		}
		var x = Math.min(Math.max((event.pageX-offset.left)-10, 0), dim.width);
		var y = Math.min(Math.max((event.pageY-offset.top)-10, 0), dim.height);
		
		var score = {
			param1: Math.round((((x/dim.width)*2)-1)*10)/10,
			param2: Math.round((((y/dim.height)*2)-1)*10)/10
		}
		
		return score;
	},
	resetFonts: function(){
		$('.coords .system').find('div').css('font-size', '');
	}
}

var home = {
	activeSlide: 'completeness',
	queue: null,
	fullSlide: function(html){
		$('.profile_container').eq(2).html(html);
		$("#profiles").animate({"left": -960}, { duration: 800, complete: function(){
			$('.profile_container').eq(0).css('display', 'none');
			$('.profile_container').eq(1).css('display', 'block').html($('.profile_container').eq(2).html());
			$("#profiles").css('left', 0);
			if (self.queue) self.queue();
		}});
	},
	clearPaging: function(){
		$('.home .paging a').removeClass('active');
	},
	showNewest: function(elm){
		$("#profiles").animate({"left": -960}, { duration: 800 });
		this.clearPaging();
		$(elm).addClass('active');
		return;
		if ('newest' != this.activeSlide)
		{
			this.clearPaging();
			$(elm).addClass('active');
			this.activeSlide = 'newest';
			this.fullSlide($('#profiles_newest').html());
		}
	},
	showTop8: function(elm){
		$("#profiles").animate({"left": 0}, { duration: 800 });
		this.clearPaging();
		$(elm).addClass('active');
		return;
		if ('top8' != this.activeSlide)
		{
			this.clearPaging();
			$(elm).addClass('active');
			this.activeSlide = 'top8';
			this.fullSlide($('#profiles_top8').html());
		}
	},
	showWildcards: function(elm){
		$("#profiles").animate({"left": -2880}, { duration: 800 });
		this.clearPaging();
		$(elm).addClass('active');
		return;
		if ('wildcards' != this.activeSlide)
		{
			this.clearPaging();
			$(elm).addClass('active');
			this.activeSlide = 'wildcards';
			this.fullSlide($('#profiles_wildcards').html());
		}
	},
	showCompleteness: function(elm){
		$("#profiles").animate({"left": -1920}, { duration: 800 });
		this.clearPaging();
		$(elm).addClass('active');
		return;
		if ('completeness' != this.activeSlide)
		{
			this.clearPaging();
			$(elm).addClass('active');
			this.activeSlide = 'completeness';
			this.fullSlide($('#profiles_completeness').html());
		}
	}
}

/*
var roller = {
	$profilelisting: null,
	$profiles: null,
	interval: null,
	group: 'completeness',
	offset: 16,
	data: [],
	maxLeft: 0,
	prepare: function(){
		this.$profilelisting = $('#content .profilelisting');
		this.$profilelisting
			.mousemove(roller.roll)
			.hover(roller.roll, roller.stopRoll);
			
		this.$profiles = this.$profilelisting.find('#profiles');
	},
	factor: function(event){
		var offset  = this.$profilelisting.offset();
		var $pwidth = this.$profilelisting.width();
		var x = Math.round(((event.pageX-offset.left)-($pwidth/2))/($pwidth/2)*100)/100;
		if (x >= 0.2)
		{
			x -= 0.2;
		}
		else if (x <= -0.2)
		{
			x += 0.2;
		}
		else if (x < 0.2 && x > -0.2)
		{
			x = 0;
		}
		return x;
	},
	roll: function(event){
		//clearInterval(roller.interval);
		
		roller.$profiles.animate({
			left: (parseInt(roller.$profiles.css('left'))-(960*roller.factor(event)))
		}, {
			duration: 1000,
			easing: 'linear',
			queue: false
		});
		/*
		roller.interval = setInterval(function(){
			var factor = roller.factor(event)*-5;
			
			var newLeft = Math.round(parseInt(roller.$profiles.css('left')) + factor);
			if (newLeft > 0)
			{
				newLeft = 0;
			}
			
			/*
			if (newLeft < -10 && newLeft < roller.maxLeft && (Math.round(newLeft/3)*3)%480 == 0 && !((Math.round(newLeft/3)*3)%960 == 0))
			{
				roller.maxLeft = newLeft;
				roller.loadData(roller.offset);
				roller.offset += 8;
			}
			* /
			
			roller.$profiles.css('left', newLeft);
		}, 20);
		* /
	},
	stopRoll: function(event){
		clearInterval(roller.interval);
	},
	loadData: function(offset){
		$.post(global_url + 'ajax/roller/' + roller.group, {
			offset: offset
		}, function(data){
			roller.$profiles
				.css('width', parseInt(roller.$profiles.css('width'))+960)
				.find('.clear').before('<div class="profile_container">' + data.join(' ') + '</div>');
			
			/*var container = roller.$profiles.find('.profile_container:last');
			for (var n = 0; n < data.length; n++)
			{
				container.append(data[n]);
			}* /
			//roller.data = roller.data.concat(data);
			//console.log(data);
		}, 'json');
	}
}
*/