$(document).ready(function(){
/*
$('.button, textarea, input, select, .rating').corner('3px');
$('.box').corner('3px');
$('.pager, .center .off, .box_info.ok, .box_info.err, .box_info.att, .box_info.info').corner('6px');
$('.info_pub').corner('3px');

$(".menuLeft li a").hover(
	function () {
		$(this).stop().animate({ paddingLeft: "45px" }, 200);
	}, 
	function () {
		$(this).stop().animate({ paddingLeft: "30px" });
	}
);
*/
$('.podpis_imie').before('<b>Imię i nazwisko:&nbsp;</b>');
$('.podpis_nazwisko').before('<b>Email:&nbsp;</b>');


$('input[type=text][title!=""]').each(function() {
	if ($.trim($(this).val()) == '') $(this).val($(this).attr('title'));
	if ($(this).val() == $(this).attr('title')) $(this).addClass('InputTextInside');
}).focus(switchText).blur(switchText);

$('form').submit(function() {
	$(this).find('input[type=text][title!=""]').each(function() {
		if ($(this).val() == $(this).attr('title')) $(this).val('');
	});
});

$('input[name=link]').change(function() {
var yt = $('input[name=link]').attr('value');

$.post("/Lotniska-video/id/", { id: yt },
   function(data) {
      jQTubeUtil.video(data, function(response){
      $('#title').attr('value', response.videos[0].title);
      $('#contentf').attr('value', response.videos[0].description);
       });
$('.box .qform').append('<object width="570" height="416"><param name="movie" value="http://www.youtube.com/v/'+data+'?version=3&amp;hl=pl_PL"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+data+'?version=3&amp;hl=pl_PL" type="application/x-shockwave-flash" width="570" height="416" allowscriptaccess="always" allowfullscreen="true"></embed></object>');       
   });

});
/*
$('img.greyscale').each(function(){
grayscale(this);
});

$('img.greyscale').hover(function(){
grayscale.reset(this);
}, function(){
grayscale(this);
})
*/

var max_size = 490;

$("article p img").each(function(i) {
  if ($(this).height() > $(this).width()) {
    var h = max_size;
    var w = Math.ceil($(this).width() / $(this).height() * max_size);
  } else {
    var w = max_size;
    var h = Math.ceil($(this).height() / $(this).width() * max_size);
  }
  $(this).css({ height: h, width: w });
});

});



/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/

function slideSwitch(nav) {
    var $active = $('#slideshow DIV.active');

    if ( $active.length == 0 ) $active = $('#slideshow DIV:last');

    // use this to pull the divs in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow DIV:first');
		
    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
		if (nav == 'prev')
			var $next  = $active.prev();


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });

}

$(function() {
    setInterval( "slideSwitch()", 4000 );
});


function switchText()
{
	if ($(this).val() == $(this).attr('title'))
		$(this).val('').removeClass('InputTextInside');
	else if ($.trim($(this).val()) == '')
		$(this).addClass('InputTextInside').val($(this).attr('title'));
}

function grayscaleImageIE(imgObj)
{
	imgObj.style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(grayScale=1)';
}

function grayscaleImage(imgObj)
{
	var canvas = document.createElement('canvas');
	var canvasContext = canvas.getContext('2d');
	
	var imgW = imgObj.width;
	var imgH = imgObj.height;
	canvas.width = imgW;
	canvas.height = imgH;
	
	canvasContext.drawImage(imgObj, 0, 0);
	var imgPixels = canvasContext.getImageData(0, 0, imgW, imgH);
	
	for(var y = 0; y < imgPixels.height; y++){
		for(var x = 0; x < imgPixels.width; x++){
			var i = (y * 4) * imgPixels.width + x * 4;
			var avg = (imgPixels.data[i] + imgPixels.data[i + 1] + imgPixels.data[i + 2]) / 3;
			imgPixels.data[i] = avg; 
			imgPixels.data[i + 1] = avg; 
			imgPixels.data[i + 2] = avg;
		}
	}
	
	canvasContext.putImageData(imgPixels, 0, 0, 0, 0, imgPixels.width, imgPixels.height);
	return canvas.toDataURL();
}


function uif_zobacz(sid) {
$('div.results').load('/jquery/uif_zobacz?sid=' + sid);
}


function uif_usun(sid, file) {
$('div[rel*="' + file + '"]').load('/jquery/uif_usun?sid=' + sid + ';' + file);
}

function uif_usun_wszystko(sid) {
$('div.results').load('/jquery/uif?sid=' + sid);
$('div.galeria').remove();
}

function redirection()
{

var index = document.form1.user.selectedIndex;
var val = document.form1.user[index].value;
alert(val); //*** it doesn't show any option
document.location="menu_editar_cliente.jsp?usr=" + document.form1.user[index].value;
}

