
Array.prototype.end = function() {

	return this[this.length - 1];

}

var Class = {

	create : function() {

		return function() {

			this.initialize.apply(this, arguments);

		}

	}

}

var Gmenu = Class.create();

Gmenu.prototype = {

	tab : "gl-menu",

	menus : new Array,

	initialize : function() {

		a = this._id(this.tab).getElementsByTagName("a");

		for ( var i = 0; i < a.length; i++) {

			rel = String(a[i].getAttribute("rel"));

			this.menus.push(rel);

			this.preloadImages(a[i].childNodes[0].src);

			if (rel == initialMenu[0]) {

				this.changeImage(a[i]);

				this.changeMenu(rel);

			}

			a[i].onmouseover = function() {

				Gmenu.prototype.changeImage(this);

				Gmenu.prototype.changeMenu(this.rel);

			}

			// a[i].onclick = function(){return false;}

			a[i].onfocus = function() {
				this.blur();
			}

		}

	},

	changeImage : function(id) {

		a = this._id(this.tab).getElementsByTagName("a");

		for ( var i = 0; i < a.length; i++) {

			n = a[i].childNodes[0].src.split('.');

			a[i].childNodes[0].src = a[i].childNodes[0].src.replace("1."
					+ n.end(), "2." + n.end());

		}

		n = id.childNodes[0].src.split('.');

		id.childNodes[0].src = id.childNodes[0].src.replace("2." + n.end(),
				"1." + n.end());

	},

	changeMenu : function(rel) {

		for ( var i = 0; i < this.menus.length; i++) {

			if (this._id(this.menus[i]))

				this._id(this.menus[i]).style.display = "none";

		}

		if (this._id(rel))

			this._id(rel).style.display = "block";

	},

	preloadImages : function(name) {

		n = name.split(".");

		img = new Image();

		img.src = name.replace("2." + n.end(), "1." + n.end());

	},

	_id : function(id) {

		return document.getElementById(id);

	}

}

// zmina styli *****************************************************************

$(document).ready(function() {

	new Gmenu();

	$('#animControl a img').click(function() {

		zmienstyl(this.getAttribute("id"));

		return false;

	});

	var c = readCookie('styl');

	if (c) {
		zmienstyl(c);
	} else {
		embedFlashTop();
	}

});

function changeElement(nazwa) {

	if (nazwa == 'noFlash') {

		$('#animControl a img').attr('src', 'images/animOn.png');

		$('#animControl a img').attr('id', 'standard');

		$('#napisy').css('display', 'none');

	}

	if (nazwa == 'standard') {

		$('#animControl a img').attr('src', 'images/animOff.png');

		$('#animControl a img').attr('id', 'noFlash');

		$('#napisy').css('display', 'block');

		embedFlashTop();

	}

}

function embedFlashTop() {

	var flashvars2 = {
		rand : 1
	};

	var params2 = {
		menu : "false",
		wmode : "transparent",
		allowscriptaccess : "sameDomain"
	};

	var attributes2 = {
		id : "anim1"
	};

	swfobject.embedSWF("swf/napisy.swf", "anim1", "760", "130", "10.0.0.0",
			"anim1", flashvars2, params2, attributes2);

}

function zmienstyl(styleName)

{

	$('link[rel*=style][title]').each(function(i)

	{

		this.disabled = true;

		if (this.getAttribute('title') == styleName)
			this.disabled = false;

	});

	changeElement(styleName);

	createCookie('styl', styleName, 365);

}

// cookie functions http://www.quirksmode.org/js/cookies.html

function createCookie(name, value, days)

{

	if (days)

	{

		var date = new Date();

		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));

		var expires = "; expires=" + date.toGMTString();

	}

	else
		var expires = "";

	document.cookie = name + "=" + value + expires + "; path=/";

}

function readCookie(name)

{

	var nameEQ = name + "=";

	var ca = document.cookie.split(';');

	for ( var i = 0; i < ca.length; i++)

	{

		var c = ca[i];

		while (c.charAt(0) == ' ')
			c = c.substring(1, c.length);

		if (c.indexOf(nameEQ) == 0)
			return c.substring(nameEQ.length, c.length);

	}

	return null;

}

function eraseCookie(name)

{

	createCookie(name, "", -1);

}

// /cookie functions

$(document).ready(function() {
	
	imieS='Twoje imię';
	emailS='e-mail';
	
	$('#imieS').val(imieS);
	$('#emailS').val(emailS);
	$('#imieS').click(function(){
		if($('#imieS').val()==imieS){ $('#imieS').val(''); }
		});
	$('#emailS').click(function(){
		if($('#emailS').val()==emailS){ $('#emailS').val(''); }
		});
	
	$('#emailS').focusout(function(){
		if($('#emailS').val()==''){ $('#emailS').val(emailS); }
		});
	$('#imieS').focusout(function(){
		if($('#imieS').val()==''){ $('#imieS').val(imieS); }
		});
	
	$('#newsletterStopka').submit(function() {
		
		if($('#imieS').val()==imieS){ $('#imieS').val(''); }

		$(this).attr('action', "newsletter/newsletter-xhr.php");
		$.ajax( {
			type : $(this).attr('method'),
			url : $(this).attr('action'),
			data : $(this).serialize(),
			cache : false,
			dataType : 'json',

			success : function(obj) {

				// alert(obj.status);

			if (obj.status == 1) {

				$('#newsletterStopka').fadeOut('slow', function() {

					$('#newsletterDescStopka').html(obj.opis);

					$('#newsletterDescStopka').show('fast');

				});

			}

			else {

				$('#newsletterDescStopka').html(obj.opis);

				$('#newsletterDescStopka').slideDown('fast');

			}

			// zmiana koloru pól

			if (obj.status == 5) {

				$('#imieS').css( {

					border : '1px solid #c30000'

				});

				$('#emailS').css( {

					border : '1px solid #9acae9'

				});

			}

			if (obj.status == 2 || obj.status == 3) {

				$('#emailS').css( {
					border : '1px solid #c30000'
						
				});
				
				$('#imieS').css( {

					border : '1px solid #9acae9'

				});
				
					
				
			}

		}

		});

		return false;

	});

});

