jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { //set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString();
        }
        
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { //get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

function createMp3Tag() {
	$('.mp3_player').each(function() {
		var $div = $(this);
		var $a = $(this).children('a');
		var href = $a.attr('href');
		var title = $a.attr('title');
		if (title==undefined) title = '';
		if (href==undefined) return false;
		
		var flashvars = {};
			flashvars.trackURL = href;
			flashvars.title = title;
			flashvars.width = 630;
			flashvars.height = 30;
			flashvars.autoPlay = "false";
			flashvars.autoLoad = "false";
			flashvars.downloadEnabled = "false";
			flashvars.loop = "false";
			flashvars.volume = 0.7;
			flashvars.duration = 143935;
			flashvars.color1 = "0x6c57a0";
			flashvars.color2 = "0xeeeeee";
			flashvars.color3 = "0x333333";
			flashvars.color4 = "0xeeeeee";
			flashvars.color5 = "0x6c57a0";
			flashvars.color6 = "0xeeeeee";	
			
		$div.flash({
			src: 'http://www.doman.art.pl/mp3/player.swf',
			width: 630,
			height: 30,
			flashvars: flashvars,
			wmode: 'transparent'
		});
	});

}

function animateClouds() {
	//chmurki animacja
	var ile = 10;
	var $chmurki = [];
	var maxTop = 313-259;
	var maxLeft = $(window).width();
	var minSpeed = 0.5;
	var maxSpeed = 1.8; //minSpeed + maxSpeed

	for (i=0; i<ile; i++) {
		$chmurki[i] = $('<span class="chmurka'+((Math.random(1)>0.5)?'2':'1')+'"></span>');
		if (i < ile/2) {
			$chmurki[i].left = Math.random()*(maxLeft/2);
			$chmurki[i].css('left',$chmurki[i].left);
		} else {
			$chmurki[i].left = Math.random()*(maxLeft/2) + (maxLeft/2)
			$chmurki[i].css('left',$chmurki[i].left);
		}
		$chmurki[i].css('top',Math.random()*maxTop);		
		$chmurki[i].speed = minSpeed + Math.random()*maxSpeed;
		$('.page_top').prepend($chmurki[i]);
		$chmurki[i].show();
	}

	animuj = function() {
		for (i=0; i<ile; i++) {
			var $ob = $chmurki[i];
			$ob.left = $ob.left - $ob.speed;
			$ob.css('left', $ob.left);
			if ($ob.left <= -400) {
				$ob.left = maxLeft;
				$ob.css({
					left	:	maxLeft,
					top		:	Math.random()*maxTop
				});
				$ob.speed = minSpeed + Math.random()*maxSpeed;
				$ob.removeClass().addClass('chmurka'+((Math.random(1)>0.5)?'2':'1'))
			}
		}
		setTimeout(function() {
			animuj();
		},  33);
	}
	animuj();
}

//##################################################################
$(document).ready(function() {
	//inputs placeholder
	if (!('placeholder' in document.createElement('input'))) {
		$('[placeholder]').focus(function() {
			var input = $(this);
			if (input.val() == input.attr('placeholder')) {
			input.val('');
			input.removeClass('placeholder');
		}
		}).blur(function() {
			var input = $(this);
			if (input.val() == '' || input.val() == input.attr('placeholder')) {
			input.addClass('placeholder');
			input.val(input.attr('placeholder'));
		}
		}).blur();
		//send form
		$('[placeholder]').parents('form').submit(function() {
			$(this).find('[placeholder]').each(function() {
				var input = $(this);
				if (input.val() == input.attr('placeholder')) {
					input.val('');
				}
			})
		});
	}

	//zamieniam linki z mp3 na flashaplayera
	createMp3Tag();

	//animacja chmurek tylko dla większych ekranow
	if ($(window).width()>760) {
		animateClouds();
	} else {
		$('.wpis img').removeAttr('width').removeAttr('height');
	}


	//obrazki na stronie
	$('.rysunek').each(function() {
		var href = $(this).attr('src');
		$(this).wrap('<a class="lightbox" href="'+href+'"></a>');
	});

	$("a.lightbox").colorbox({
		'overlayClose':true,
		'scalePhotos':false
	});

	//super komputer Fantomasa
    $("a.see_more_graphic").colorbox({
		'innerWidth' : 980,
		'innerHeight' : 650,
		'iframe' : true,
		'overlayClose':true,
		'scrolling' : false
	});
});
