$(document).ready(function(){
	$(".motodataBox").hide();
	$(".motodataContener").hide();

	$(".partsBox a").click(function(event){
		$(".partsBox").hide();
		$(".partsContener").hide();
		$(".motodataBox").show();
		$(".motodataContener").show();

	});

	$(".motodataBox a").click(function(event){
		$(".partsBox").show();
		$(".partsContener").show();
		$(".motodataBox").hide();
		$(".motodataContener").hide();

	});
});


function seo(str)
{
	var url = str
		.toLowerCase() // change everything to lowercase
		.replace(/^\s+|\s+$/g, "") // trim leading and trailing spaces
		.replace(/[_|\s|\/]+/g, "-") // change all spaces and underscores to a hyphen
		.replace(/[^a-z0-9-]+/g, "") // remove all non-alphanumeric characters except the hyphen
		.replace(/[-]+/g, "-") // replace multiple instances of the hyphen with a single instance
		.replace(/^-+|-+$/g, "") // trim leading and trailing hyphens
		;
	return url;
}


var switch_array = new Array();
var switch_duration = 300;
var switch_duration_onload = 0;

/* zwija/rozwija poddzialy */
function switch_link(switcher_id, id, mode)
{
	if(typeof(mode) == 'undefined')
	{
		mode = 'toggle';
	}

	if(mode == 'toggle')
	{
		$('#' + id).slideToggle (switch_duration, function() {
			if(! $('#' + id).is(':hidden') )
			{
				$('#' + switcher_id).removeClass('switcherPlus');
				$('#' + switcher_id).addClass('switcherMinus');
				switch_loger(id, 1);
			}
			else
			{
				$('#' + switcher_id).removeClass('switcherMinus');
				$('#' + switcher_id).addClass('switcherPlus');
				switch_loger(id, -1);
			}

		});
	}
	else if(mode == 'down')
	{
		$('#' + id).slideDown(switch_duration_onload);
		$('#' + switcher_id).removeClass('switcherPlus');
		$('#' + switcher_id).addClass('switcherMinus');
	}
	else if(mode == 'up')
	{
		$('#' + id).slideUp(switch_duration_onload);
		$('#' + switcher_id).removeClass('switcherMinus');
		$('#' + switcher_id).addClass('switcherPlus');
	}

}

/* loguje w tablicy switch_array akcje usera */
function switch_loger(id, operation)
{
	var switch_array_element = new Array();
	var added = false;

	switch_array_element[0] = id;
	switch_array_element[1] = operation;


	for (i in switch_array)
	{
		if(switch_array[i][0] == switch_array_element[0])
		{
			switch_array[i] = switch_array_element;
			added = true;
		}
	}
	if(!added) switch_array.push(switch_array_element);

	switch_save();
}

/* zapisuje log switchow w cookie */
function switch_save()
{
	var switch_to_save = '';

	for (var i = 0; i < switch_array.length; i++)
	{
		if(typeof(switch_array[i][0]) != 'undefined')
		{
			switch_to_save += switch_array[i][0] + ',' + switch_array[i][1] + ';';
		}
	}
	Cookie.set('switch_log', switch_to_save, 0.1);

}

/* odczytuje log switchow z cookie */
function switch_read()
{
	var cookie;
	cookie = Cookie.get('switch_log');

	switch_array = new Array();
	if (cookie) {
		var cookie_array = cookie.split(';');
		for (var i = 0; i < cookie_array.length; i++)
		{
			var cookie_array2 = cookie_array[i].split(',');
			var id = cookie_array2[0];
			var switcher_id = cookie_array2[0] + '-s';
			if(id != '')
			{
				switch_array[i] = cookie_array2;

				if(cookie_array2[1] == 1)
				{
					switch_link( switcher_id , id, 'down');
				}
				else
				{
					switch_link( switcher_id , id, 'up');
				}
			}
		}
	}
}


var Cookie = {
	set: function(name, value, daysToExpire) {
		var expire = '';
		if (daysToExpire != undefined) {
			var d = new Date();
			d.setTime(d.getTime() + (86400000 * parseFloat(daysToExpire)));
			expire = '; expires=' + d.toGMTString();
		}
		return (document.cookie = escape(name) + '=' + escape(value || '') + expire);
	},
	get: function(name) {
		var cookie = document.cookie.match(new RegExp('(^|;)\\s*' + escape(name) + '=([^;\\s]*)'));
		return (cookie ? unescape(cookie[2]) : null);
	},
	erase: function(name) {
		var cookie = Cookie.get(name) || true;
		Cookie.set(name, '', -1);
		return cookie;
	}
};


$.extend($.validator.messages, {
	required: "Pole jest wymagane",
	email: "Format adresu email jest nieprawidłowy"
});	