function mycarousel_initCallback(carousel) {
    jQuery('#nextBtn').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#prevBtn').bind('click', function() {
        carousel.prev();
        return false;
    });
};

var cho = 0;
var mc = 0;
$(document).ready(function(){

	$("#dodawanie_left #list a").click(function(){
		var id = $(this).attr('id');
		var _id = id.split("_");
		id = _id[0];
		_mc = _id[1];
		if($(this).hasClass("choosen")){
			if(cho > 0){
				cho = cho - 1;
				$(this).removeClass("choosen");
				if(cho > 0)	{
					var ci = '';
					$("#dodawanie_left #list a.choosen").each(function(){					
						ci = ci + $(this).attr('id').substring(1)+';';
					});
					$("#category").val(ci);
				}
				else {
					mc = 0;
					$("#category").val('');
				}
			}
		}
		else{
			if(cho == 0) mc = _mc;
			if(cho < 3 && _mc == mc){
				cho = cho + 1;
				//$("ul li a").removeClass("choosen");
				$(this).addClass("choosen");
				var ci = '';
				$("#dodawanie_left #list a.choosen").each(function(){					
					ci = ci + $(this).attr('id').substring(1)+';';
				});
				$("#category").val(ci);
			}
		}
		return false;
	});

	$("#photos .photo .photo_link a").click(function(){
		var id = $(this).attr('id').substring(3);
		$.ajax({
			type: "POST",
			url: "katalog/ajax_del_photo",
			data: "id="+id+"&null=1",
			success: function(content) {
				$.getScript('js/function.js');
				$("#photos").html(content);
			}
		});
		return false;
	});

	$("#mapapolski li a").hover(function(){
		var id = $(this).parent().attr('id').substring(1);
		$("#wojlistbox"+id+" .arrowlist").addClass('arrowlistshow');
		$("#wojlist"+id).addClass('hover');
	}, function(){
		var id = $(this).parent().attr('id').substring(1);
		$("#wojlistbox"+id+" .arrowlist").removeClass('arrowlistshow');
		$("#wojlist"+id).removeClass('hover');
	});

	$("#mapawojslist a, #mapawojslist2 a").hover(function(){
		var id = $(this).attr('id').substring(7);
		$("#wojlistbox"+id+" .arrowlist").addClass('arrowlistshow');
		$("#mapapolski #m"+id+" .bg").addClass('maphover');
	}, function(){
		var id = $(this).attr('id').substring(7);
		$("#wojlistbox"+id+" .arrowlist").removeClass('arrowlistshow');
		$("#mapapolski #m"+id+" .bg").removeClass('maphover');
	});

	$(".star-vote li a").click(function () {
		$(".current-vote").css({'width':($(this).attr('title')*20)+'%'});
		$("#vote").val($(this).attr('title'));
		return false;
	});


	$(".vote_plus").change(function(){
		var ef = 0;
		$(".vote_plus").each(function(){
			if($(this).val().length < 1)
				ef += 1;
		});	
		if(ef <= 1)
			$("#com_plusy").append('<div class="bg_input2"><div class="bg_input_label4"><img src="templates/home/plus.png" alt="" /></div><div class="bg_input_field3"> '+
						'<input type="text" name="plusy[]" class="input1 vote_plus" style="width: 160px;" /></div></div>');
	});

	$(".vote_minus").change(function(){
		var ef = 0;
		$(".vote_minus").each(function(){
			if($(this).val().length < 1)
				ef += 1;
		});
		if(ef <= 1)
			$("#com_minusy").append('<div class="bg_input2"><div class="bg_input_label4"><img src="templates/home/minus.png" alt="" /></div><div class="bg_input_field3"> '+
						'<input type="text" name="minusy[]" class="input1 vote_minus" style="width: 160px;" /></div></div>');
	});


});

function show(id, i){
	new_window(900);
	$.ajax({
		type: "POST",
		url: "katalog/ajax_img",
		data: "id="+id+"&i="+i+"&null=1",
		beforeSend: function(){
			$("#layer_content").html('<div style="padding: 200px 0px; text-align: center;"><img src="al.gif" style="border: 0px; width: 16px; height: 16px;" alt="" /></div>');
		},
		success: function(content) {
			$("#layer_content").html(content);
			$('.list2 ul').jcarousel({
				scroll: 5,
				initCallback: mycarousel_initCallback,
				buttonNextHTML: null,
				buttonPrevHTML: null
			});


		}
	});
}

function changeImg(id, i){
	$.ajax({
		type: "POST",
		url: "katalog/ajax_img_big",
		data: "id="+id+"&i="+i+"&null=1",
		beforeSend: function(){
			$("#wpis_main_photo").html('<div style="padding: 200px 0px; text-align: center;"><img src="al.gif" style="border: 0px; width: 16px; height: 16px;" alt="" /></div>');
		},
		success: function(content) {
			var img = new Image();
			var path = new String();
			path =  content;
			img.src = path;
			img.onload = function(){
				$("#wpis_main_photo").fadeOut(300,function(){
					$("ul#mycarousel li").css({'border-color' : '#ffffff'});
					$("#img"+i+"").css({'border-color' : '#8ec90d'});
					$(this).html(img).fadeIn(800);
				});
			}
		}
	});
}

function new_window(wid){
	if($('#layer')) $('#layer').remove();
	var wid2 = wid+38;
	var z = (screen.width-wid2-18)/2;

	var shadow1 = '<div id="lay_rel">' +
		'<div id="layer_x"><input type="button" class="layer_x" onclick="closeWindow();" /></div>'+
		'<div class="layer_tl"></div><div class="layer_t" style="width: '+wid+'px;"></div>'+
		'<div class="layer_tr"></div><div class="clear"></div>';
	var shadow2 = '<table cellpadding="0" cellspacing="0" border="0">'+
		'<tr><td class="layer_l"></td>'+
		'<td id="layer_content" class="layer_content" style="width: '+ wid +'px;"></td>'+
		'<td class="layer_r"></td></tr></table>';
	var shadow3 = '<div class="layer_bl"></div><div class="layer_b" style="width: '+wid+'px;"></div><div class="layer_br"></div><div class="clear"></div></div>';
	var shadow = shadow1+shadow2+shadow3;

	var tdiv = $('<div id="layer" style="width: '+ wid2 +'px; position: absolute; z-index: 2000; top: 50px; left: '+ z +'px;"><div id="lay_rel"></div></div>').html(shadow);
	$("body").prepend('<div id="layer_overlay"></div>').prepend(tdiv);
	$.scrollTo( 0, 800 );
}

function closeWindow(){
	if($('#layer')) $('#layer').remove();
	if($('#layer_overlay')) $('#layer_overlay').remove();
}



function Confirm(text,location) {
	if (confirm(text)) {
		parent.location.href=location;return true;
	} else {}
}

/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);
