var cookieMonthExpire = 31;
var cookieYearExpire = 365;
var radioAction = $.browser.msie ? 'click' : 'change';
var selectAction = 'change';
var ajaxImage = new Image();
ajaxImage.src = '/public/images/busy.gif';

$(function() {
	$.fn.setMottoImages = function() {
		var countImages = 18;//number images in total
		var viewImages = 4;//don't change
		var randomImages = new Array();
		while (randomImages.length <= viewImages) {
			var useImage = false;
			var randomImage = Math.ceil(Math.random() * countImages);
			for (var i = 1; i <= randomImages.length; i++) {
				if (randomImages[i] == randomImage) {
					useImage = true;
				}
			}
			if (!useImage) {
				randomImages[randomImages.length] = randomImage;
			}
		}
		
		
		$("#MottoBoxImages").css({"display" : "none", "border-top" : "2px solid #330099", "border-bottom" : "2px solid #330099"});
		for (var j = 1; j <= viewImages; j++) {
			var name = '/public/images/motto/mottoImage' + randomImages[j] + '.jpg'
			$("#MottoBoxImages_image" + j).css({'background-image' : 'url(' + name + ')'});
		}
		$("#MottoBoxImages").fadeIn(2500);
	};
	
  $(document).ready(function() {
  	$("#MottoBoxIn").setMottoImages();
  });
});

function blockWindow(text, description) {
	var allMessage = '<div class="loading"><img src="' + ajaxImage.src + '" height="32" width="32" alt="" /> <span id="text">' + text + '</span>';
	if (description != null) {
		allMessage += '<span id="description">' + description + '</span>';
	}
	allMessage += '</div>';
	$.blockUI({ message: allMessage });
}

function unblockWindow() {
	$.unblockUI();
}

function confirm(item, msg, yes, no) {
	$(item).confirm({msg: '<strong>' + msg + '? </strong> ', yes: yes, no: no});
}

function packMenu(id, speed, title) {
	$('#' + id).css({'background' : '#FFCC00', 'border' : 0, 'margin-left' : '-20px'});
	$('#' + id + 'Top').attr({'src' : '/public/images/maximize.gif', 'alt' : title, 'title' : title});
	$('#' + id + 'In').fadeOut(speed);
}
				
function unpackMenu(id, speed, title) {
	$('#' + id).css({'background' : '#CC99FF', 'border' : '1px solid #330099', 'margin-left' : '-21px'});
	$('#' + id + 'Top').attr({'src' : '/public/images/minimize.gif', 'alt' : title, 'title' : title});
	$('#' + id + 'In').fadeIn(speed);
}

function pack(id, speed, title) {
	$('table#' + id + ' th.plus img').attr({'src' : '/public/images/maximize.gif', 'alt' : title, 'title' : title});
	$('table#' + id + ' tr.hideJS').addClass('hidden');
	$('table#' + id + ' tr.hideJS').fadeOut(speed);
}
				
function unpack(id, speed, title) {
	$('table#' + id + ' th.plus img').attr({'src' : '/public/images/minimize.gif', 'alt' : title, 'title' : title});
	$('table#' + id + ' tr.hideJS').removeClass('hidden');
	$('table#' + id + ' tr.hideJS').fadeIn(speed);
}

function setProductCookies(size, colour, dullness, domain, path) {
	$.cookie('productSize', size, { expires: cookieMonthExpire, path: path });
	$.cookie('productColour', colour, { expires: cookieMonthExpire, path: path });
	$.cookie('productDullness', dullness, { expires: cookieMonthExpire, path: path });
}

function setAdditionalProductCookies(userActivation_code, additionalProduct_id, count, domain, path) {
	$.cookie(userActivation_code + '_additionalProduct_id', additionalProduct_id, { expires: cookieMonthExpire, path: path });
	$.cookie(userActivation_code + '_additionalProductCount', count, { expires: cookieMonthExpire, path: path });
}

function starsUp(picture_id, num) {
	for (var i = 1; i <= 10; i++) {
		var starName = 'star_' + picture_id + '_' + i;
		if (i <= num) {
			$('#' + starName).attr({'src' : '/public/images/fullStar.gif'});
		} else {
			$('#' + starName).attr({'src' : '/public/images/emptyStar.gif'});
		}
	}
}

function starsOut(picture_id, num) {
	for (var i = 1; i <= 10; i++) {
		var starName = 'star_' + picture_id + '_' + i;
		if (i <= num) {
			$('#' + starName).attr({'src' : '/public/images/fullStar.gif'});
		} else {
			$('#' + starName).attr({'src' : '/public/images/emptyStar.gif'});
		}
	}
}