$(document).ready(function() {
	jQuery('#mycarousel').jcarousel({
        vertical: true,
        scroll: 1
    });
	//inicjacja

	//product
	fotoZoom();
	$('#panning_contener').jqm();
	//vertical window_panning
	if($('#panning_window').length) {
		var jqm_height = $('#panning_contener').outerHeight();
		var stage_height = $(window).height();
		if(stage_height > jqm_height)
			{
				var difference = (stage_height - jqm_height)/2;
				$('#panning_contener').css('top', difference+'px');
			}
		else
		{
			$('#panning_contener').css('top', '0px');
		}
		
		$(window).resize(function() {
			var jqm_height = $('#panning_contener').outerHeight();
			var stage_height = $(window).height();
			if(stage_height > jqm_height)
				{
					var difference = (stage_height - jqm_height)/2;
					$('#panning_contener').css('top', difference+'px');
				}
			else {
				$('#panning_contener').css('top', '0px');
			}
		});
	}

	//tooltips
	/*$('#customize span.tooltip').tooltip({
	    track: true,
	    top: -130,
		left: -150,
	    delay: 0,
	    showURL: false,
	    showBody: " - ",
	    fade: 250,
	    extraClass: "preview",
	});*/
	$('input[name=custom_plate], input[name=custom_place]').change(function() {
		var contener = $(this).parent();
		var id = 'img_'+contener.attr('id');
		//contener.html(content);
		$('#'+id).fadeIn();
		setTimeout( function(){
			$('#'+id).fadeOut();
		}, 1000 );

		var nm = $(this).attr('name');
		if(nm=='custom_plate') {
			var o = $(this).val();
			$('.place_option').hide();
			if(o == 'logo')
			{
				$('#plate_img').show();
			}
			else {
			$('#plate_text').show();	
			}
		}
	});

	//produkt - wybor skory i podszewki
	$('#btn_choose_lining').click(function() {
		$('div.tohide').fadeOut(300).removeClass('tohide');
		$('.choose_lining').fadeIn(300).addClass('tohide');
		});

	$('#btn_choose_plate').click(function() {
		$('div.tohide').fadeOut(300).removeClass('tohide');
		$('.choose_plate').fadeIn(300).addClass('tohide');
		});

	$('#btn_choose_leather').click(function() {
		$('div.tohide').fadeOut(300).removeClass('tohide');
		$('.choose_leather').fadeIn(300).addClass('tohide');
		});

	$('#btn_choose_place').click(function() {
		$('div.tohide').fadeOut(300).removeClass('tohide');
		$('.choose_place').fadeIn(300).addClass('tohide');
		});
	
	
	$('.rollout_choice').click(function() {
	$(this).parent().fadeOut(300);
	$('.choose_leather').fadeOut(300);
	$('.choose_place').fadeOut(300);
	$('.choose_plate').fadeOut(300);
	});
		
	$('div.leather-b-out').click(function() {
		$('.choose_leather').fadeOut(300);
		$('.choose_lining').fadeOut(300);
		$('.choose_place').fadeOut(300);
		$('.choose_plate').fadeOut(300);
	});
	
	$('div.leather_btn').click(function() {
	$('.leather_thumb').css('display', 'none');
	var choosed = $(this).attr('rel');
	$('input[name=leather]').val(choosed);
	$('#'+choosed).css('display', 'inline-block');
	$('.choose_leather').fadeOut(300);
	});

	$('div.lining_btn').click(function() {
		$('.lining_thumb').css('display', 'none');
		var choosed = $(this).attr('rel');
		$('input[name=lining]').val(choosed);
		$('#'+choosed).css('display', 'inline-block');
		$('.choose_lining').fadeOut(300);
		});
	
	$('div.place_btn').click(function() {
		$('.place_thumb').css('display', 'none');
		var choosed = $(this).attr('rel');
		$('input[name=custom_place]').val(choosed);
		$('#'+choosed).css('display', 'inline-block');
		$('.choose_place').fadeOut(300);
		});

	$('div.plate_btn').click(function() {
		$('.plate_thumb').css('display', 'none');
		var choosed = $(this).attr('rel');
		$('input[name=custom_plate]').val(choosed);
		$('#'+choosed).css('display', 'inline-block');
		$('.choose_plate').fadeOut(300);
		
		var o = $(this).attr('rel');
			$('.place_option').hide();
			if(o == 'logo')
			{
				$('#plate_img').show();
			}
			else {
			$('#plate_text').show();	
			}
		});

	//categories
	$('.block_img_contenter').hover(function(){
		var id = $(this).attr('id');
		$('#'+id+' img').toggleClass('hidden');
	}, function() {
		var id = $(this).attr('id');
		$('#'+id+' img').toggleClass('hidden');
	});
	torebki_menu();


	//koszyk sklepowy
	shopcartInit();
	
	$('#order_final').live('click', function() {
		if($('input[name=permit]').is(":checked") == false)
		{
			jAlert('musisz zaakceptować regulamin', 'Sabrina Pilewicz');
		return false;
		}
		var paymentType = $("#paymentOptions input:radio:checked").val();
		switch(parseInt(paymentType))
		{
		case 1:
			location.href = 'shopcart_paymentok.html&payment_type=przelew';
			break;
		case 2:
			location.href = 'shopcart_paymentok.html&payment_type=przy_odbiorze';
			break;
		case 3: 
			document.payform.submit();
			break;
		default:
			location.href = 'shopcart_details.html';
			break;
		}
	});

	//wybor platnosci
	$("input[name='paymentType']").livequery('click', function(){
		var platnosci_pl = $('#platnosci_pl');
	    if ($(this).val() == 3)
	    {
	    	platnosci_pl.css('display', 'block');
	    }
	    else
	    {
	    	platnosci_pl.css('display', 'none');
	    }
	});
	
	$('img[id^=pay-]').live('click', function() {
		var payType = $(this).attr('id').substring(4);
		$('#pay_type').val(payType);
		$('img.paymentChoice').removeAttr('class');
		$(this).attr('class', 'paymentChoice');
	});


	$(".lightbox").lightbox(); 
});
function change_foto(new_img)
{
	$("#image_preview_contener").load('medfoto.php?foto='+new_img);
	$('#btn_panning').click(function() {
		showPanning(new_img);
	});
}
function fotoZoom()
{
		var opcje = {
	    zoomWidth: 315,
	    zoomHeight: 450,
            xOffset: 100,
            yOffset: -21,
            position: "right",
            title: false,
			preloadText: '<img src="images/ajax-loader.gif" />'
};
$('#medium_preview').jqzoom(opcje);
}

function showPanning(adres)
{
	 var flashvars = {'linkFoto': adres};
	 var params = {'wmode': 'transparent'};
	 var attributes = {'id':'panning_window', 'name':'panning_window'};
	swfobject.embedSWF("swf/panning.swf", "panning_window", "100%", "100%", "9.0.0","swf/panning.swf", flashvars, params, attributes);
}

function hidePanning() {
	$('#panning_contener').jqmHide();
}

function torebki_menu()
{
	$('li.torebki_lvl1, li.torebki_lvl2').hover(
	function() {
		var id = $(this).attr('id').substring(3);
		$('#subs_'+id).toggleClass('hidden');
	},
	function() {
			var id = $(this).attr('id').substring(3);
			$('#subs_'+id).toggleClass('hidden');
		});
}

function photoUp(event, queueID, fileObj, response, data)
{
var dims = '&width=250&height=80&normal';
var url = 'images.php?picture=buffer/uploads/'+fileObj.name+dims;
var htm = '<img id="uploadedImg" src="'+url+'" alt="brak obrazka" />';
$('#loadedImg').html(htm).fadeIn('slow');
$('#custom_img').val(fileObj.name);
$('#img_logo_contenter').height(200);
}
