$(document).ready(function(){
	$('a').focus(function(){
		$(this).blur();
	});
	
	$('.menu-link, .footer-menu-link').mouseover(function(){
		$(this).addClass("over");
	});
	
	$('.menu-link, .footer-menu-link').mouseout(function(){
		$(this).removeClass("over");
	});
});

function removeFocusOnLinks() {
	$('a').focus(function(){
		$(this).blur();
	});
}

function resizeProgramItems() {
	var maxHeight = 0;
	
	$('.program-items-container').each(function(index, element) {
		var correctheight = $(element).height() - 20; //minus the padding of the box
		$(element).children().height(correctheight);
	});
}

function resizeGameItems() {
	var maxHeight = 0;
	$('.game-item').each(function(index, element) {
		if($(element).height() > maxHeight)
			maxHeight = $(element).height();
	});
	
	$('.game-item').each(function(index, element) {
		$(element).height(maxHeight);
	});
}

function getProductsList(productsContainerId, productTypeId, displayTypeId, minPrice, maxPrice, limit, order) {
	$.ajax({
		url: WEBROOT + 'products/getProducts',
		type: 'POST',
		dataType: 'json',
		cache: false,
		data: {
			productTypeId: productTypeId,
			displayTypeId: displayTypeId,
			minPrice: minPrice,
			maxPrice: maxPrice,
			limit: limit,
			order: order
		},
		success: function(data) {
			updateProductsList(data, productsContainerId);
		},
		beforeSend: function() {
			$('#'+productsContainerId).html('<div class="loader"><img title="Loading" alt="Loading" src="' + WEBROOT + 'img/ajax-loader.gif" /></div>');
		}
	});
}

function getGamesList(gamesContainerId, typeId, limit, order, isTopGame) {
	$.ajax({
		url: WEBROOT + 'games/getGames',
		type: 'POST',
		dataType: 'json',
		cache: false,
		data: {
			typeId: typeId,
			limit: limit,
			order: order,
			isTopGame: isTopGame
		},
		success: function(data) {
			updateGamesList(data, gamesContainerId);
			resizeGameItems();
		},
		beforeSend: function() {
			$('#'+gamesContainerId).html('<div class="loader"><img title="Loading" alt="Loading" src="' + WEBROOT + 'img/ajax-loader.gif" /></div>');
		}
	});
}

function getProgramsList(programsContainerId, typeId, programCategoryId, winningsPercentage, game1, game2, game3, game4, limit, order, group) {
	$.ajax({
		url: WEBROOT + 'programs/getPrograms',
		type: 'POST',
		dataType: 'json',
		cache: false,
		data: {
			typeId: typeId,
			programCategoryId: programCategoryId,
			winningsPercentage: winningsPercentage,
			game1: game1,
			game2: game2,
			game3: game3,
			game4: game4,
			limit: limit,
			order: order,
			group: group
		},
		success: function(data) {
			updateProgramsList(data, programsContainerId);
			resizeProgramItems();
		},
		beforeSend: function() {
			$('#'+programsContainerId).html('<div class="loader"><img title="Loading" alt="Loading" src="' + WEBROOT + 'img/ajax-loader.gif" /></div>');
		}
	});
}

function sendContactMessage(contactFormResponseContainer, contactName, contactEmail, contactMessage) {
	$.ajax({
		url: WEBROOT + 'products/sendContactMessage',
		type: 'POST',
		dataType: 'json',
		cache: false,
		data: {
			contactName: contactName,
			contactEmail: contactEmail,
			contactMessage: contactMessage
		},
		success: function(data) {
			contactMessageResponse(data, contactFormResponseContainer);
		}
	});
}

function getSelectedProducts(url, container) {
	$.ajax({
		type: 'GET',
		url: url,
		dataType: 'json',
		cache: false,
		success: function(response) {
			if(response['products-number'] == 0)
				$('.status-container').hide();
			else {
				$('.status-container').show();
				$('.status-container .products-number').html(response['products-number']);
				//$('.status-container .price-no-vat').html(response['price-no-vat']);
				//$('.status-container .price-with-vat').html(response['price-with-vat']);
			}
		}
	});
}
