﻿var itemPosition = 0;
var offSet = 122;

$(document).ready(function(){
	
	var leftColumnHeight = jQuery('#footer').offset().top;
	leftColumnHeight = parseInt(leftColumnHeight);
	leftColumnHeight -= 275;
	jQuery('#on_contacts').css({
		'height': leftColumnHeight
	});
/*	jQuery('#on_likes').css({
		'height': leftColumnHeight+73
	});*/
	jQuery('table.type1 tr:odd').css('background-color', '#ededed');
	jQuery('#logo').hover(
		function(){
			jQuery(this).attr('src', '/static/img/logo_hover.png');
		},
		function(){
			jQuery(this).attr('src', '/static/img/logo.png');
		}
	);
	
	jQuery('#left1').bind('click', function(){
		nextGame('left1');
	});
	
	jQuery('#right1').bind('click', function(){
		prevGame('right1');
	});
	
});

function bigMap(){
	jQuery('body').prepend(
		jQuery('<div></div>').attr('id', 'darkness')
	).prepend(
		jQuery('<div></div>').attr('id', 'bigmapFrameContainer').append(
			jQuery('<div></div>').attr('id', 'bigmapFrame')
		).prepend(
			jQuery('<div></div>').attr('id', 'closeButtonContainer').append(
				jQuery('<img />').attr({
					'id': 'closeButton',
					'src': '/static/img/close.png'
				})
			)
		)
	);
	
//	.bind('keydown', function(e){
//		if(e.keyCode == 27){
//			removeBigMap();
//		}
//	});
	
	jQuery(document).keydown(function(e){
		if(e.keyCode == 27){
			removeBigMap();
		}
	});
	
	jQuery('#closeButton').hover(
		function(){
			jQuery(this).attr('src', '/static/img/close_hover.png');
		},
		function(){
			jQuery(this).attr('src', '/static/img/close.png');
		}
	);
	
	initialize('bigmapFrame', false);
	
	jQuery('#darkness').bind('click', function(){
		removeBigMap();
	});
	
	jQuery('#closeButton').bind('click', function(){
		removeBigMap();
	});
}

function removeBigMap(){
	jQuery('#darkness').remove();
	jQuery('#bigmapFrameContainer').remove();
	jQuery('#closeButtonContainer').remove();
}

function prevGame(id){
	jQuery('#'+id).unbind();
	
	if (itemPosition <= 0 - items * offSet){
		itemPosition = 0;
		jQuery('#indexGames').css('left', itemPosition);
	}
	itemPosition -= offSet;
	jQuery('#indexGames').animate({'left': itemPosition}, 500, function(){
		jQuery('#'+id).bind('click', function(){
			prevGame(id);
		});
	});
}

function nextGame(id){
	jQuery('#'+id).unbind();
	
	if (itemPosition == 0){
		itemPosition = 0 - items * offSet;
		jQuery('#indexGames').css('left', itemPosition);
	}
	itemPosition += offSet;
	jQuery('#indexGames').animate({'left': itemPosition}, 500, function(){
		jQuery('#'+id).bind('click', function(){
			nextGame(id);
		});
	});
}

/*function sendMedia(data) {
	$.ajax({
		type: 'POST',
		url: 'http://game-insight.com/contact/sendMedia',
		data: data,
		cache: true,
		dataType: 'json'
	});
}

function sendDevelopers(data) {
	$.ajax({
		type: 'POST',
		url: 'http://game-insight.com/contact/sendDevelopers',
		data: data,
		cache: true,
		dataType: 'json'
	});
}

function sendInvestors(data) {
	$.ajax({
		type: 'POST',
		url: 'http://game-insight.com/contact/sendInvestors',
		data: data,
		cache: true,
		dataType: 'json'
	});
}

function sendAffairs(data) {
	$.ajax({
		type: 'POST',
		url: 'http://test.game-insight.com/contact/sendAffairs',
		data: data,
		cache: true,
		dataType: 'text',
		success: function(data, textStatus) {
			alert(data);
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			alert('error: '+textStatus+' '+errorThrown);
			hcClose();
		}
	});
}*/
