
<!--
$(document).ready(function() {
/**
	var tabloc = location.href.indexOf('#');
	var curtab = '';
	if(tabloc > -1) curtab = location.href.substring(tabloc+1);
	else curtab = 'personal-info';**/
var formFieldError = '<p class="formerror"><img src="layout-html/formerror.gif" /> Tämä kenttä on pakollinen!</p>';
var animation = '';

$('div.category').children('p').hide();
$('div.splasher').hide();
// $('.contact-info').hide();
$('div.splasher[@rel="default"]').show();
$('img.productimage').not('[@rel="1"]').hide();

//$('div#product-image [@rel="1"]').show();


	if(location.href.indexOf('#') > -1) {
		var current = location.href.substring(location.href.indexOf('#')+1);
		$('div.category').children('p').hide();
		$('div.splasher').hide();
		

		$('div.splasher[@rel="'+current+'"]').show();
		$('div.category[@rel="'+current+'"]').children('p').show();
	}
$('a.showproduct').click(function() {
		var elem = $(this).parent().parent().parent().parent();
		var id = $(this).attr('id');
		elem.children('div.product-details').children('div.product-image').children('img').hide();
		elem.children('div.product-details').children('div.product-image').children('img#product'+id).show();

});

$('.product-details').each(function(){
	$height = $(this).height();
	var maxheight = 0;
	$(this).find('img.productimage').each(function(){
		if($(this).height() > maxheight)
			maxheight = parseInt($(this).height());
	})

	if(maxheight > $height)
		$(this).css('height', maxheight+'px');
});


$('li.category > a').click(function() {
	$(this).blur();
	$(this).parents('li.category').children('.submenu-container').toggle();
	return false;
});

/**	$('.contact-selector').click(function() {
		var foo = $(this).val();
		$('.contact-info').hide();
		$('p.formerror').remove();
		$('tr.contact-info#contact-'+foo).show();
//		alert(foo);
	});	 **/

	$('.order').click(function() {
		var prodId = $(this).attr('rel');
		$.post('ajax.php', { prodId: prodId, amount: 1 }, function(data) { $('#cart-productlist').html(data); ajaxFunctions(); } );
	});

	ajaxFunctions();


	$('#tarjouspyynto-form').submit(function() {
		var yhteydenotto = $('.contact-selector[@name="yhteydenotto"]:checked').val();
		if(yhteydenotto != null) {
			
			var foo = $('input[@rel="'+yhteydenotto+'"]');
			
			
			if(foo.val() != "") {
				
				var viesti = $('textarea[@name="viesti"]').val();
				var value = $('input[@rel="'+yhteydenotto+'"]').val();
				var yhteyshenkilo = $('input[@name="yhteyshenkilo"]').val();
				var yritys = $('input[@name="yritys"]').val();
				var postiosoite = $('input[@name="postiosoite"]').val();
				var postinumero = $('input[@name="postinumero"]').val();
				var sahkoposti = $('input[@name="sahkoposti"]').val();
				var puhelin = $('input[@name="puhelin"]').val();
				
				var cart = $('input[@name="quantity"]');
				var cartitems = new Array;
				var iteration = 0;
				cart.each(function() {
					var product = new Array;
				
					cartitems[parseInt($(this).attr('rel'))] = parseInt($(this).val());
					product = null;
					iteration++;
				});

	
				if(value != "") {
					
					
					var elem = $('form#tarjouspyynto-form');
					animation = false;
					if(!animation) {
						
						animation = true; 
						elem.fadeOut('slow', function(){ 
						$('#content h1').parent('div').append('<p>KIITOS TARJOUSPYYNNÖSTÄNNE!<br/>Palaamme pian tarjouksen merkeissä.</p>'); 
						$.post('ajax.php', { tarjouspyynto: "true", viesti: viesti, cart: serialize(cartitems), kontaktitapa: yhteydenotto, yhteyshenkilo: yhteyshenkilo, yritys: yritys, postiosoite: postiosoite, postinumero: postinumero, sahkoposti: sahkoposti, puhelin: puhelin }, function(data) {  }  ); 
						animation = false; 
					});}
				} else {
					var errorElem = $('input[@name="contact-'+yhteydenotto+'"]').parent('td').children('p.formerror');
					if(errorElem.size() == 0) $('input[@name="contact-'+yhteydenotto+'"]').parent('td').prepend(formFieldError);
				}
				
			} else {
				var errorElem = $('input[@rel="'+yhteydenotto+'"]');
			
				errorElem.css('background', '#FFE1E1');
			}
		} else {
			var errorElem  = $('.contact-selector').parent('td').children('p.formerror');
			if(errorElem.size() == 0) $('.contact-selector').parent('td').prepend(formFieldError);
		}
		return false;
	});

});

function ajaxFunctions() {

	$('.cart-killts').click(function() {
		var prodId = $(this).attr('rel');

		$.post('ajax.php', { prodId: prodId, amount: "all" }, function(data) { $('#cart-productlist').html(data); ajaxFunctions(); } );
	});
	$('.cart-subtract').click(function() {
		var prodId = $(this).attr('rel');z
		$.post('ajax.php', { prodId: prodId, amount: -1 }, function(data) { $('#cart-productlist').html(data); ajaxFunctions(); } );
	});
	$('.cart-increase').click(function() {
		var prodId = $(this).attr('rel');
		$.post('ajax.php', { prodId: prodId, amount: 1 }, function(data) { $('#cart-productlist').html(data);  ajaxFunctions(); } );

	});

}

function serialize (a)
{
    var a_php = "";
    var total = 0;
    for (var key in a)
    {
        ++ total;
        a_php = a_php + "s:" +
                String(key).length + ":\"" + String(key) + "\";s:" +
                String(a[key]).length + ":\"" + String(a[key]) + "\";";
    }
    a_php = "a:" + total + ":{" + a_php + "}";
    return a_php;
}
-->