/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 
jQuery(document).ready(function() {
	openPage('frontpage');
});

 
function openShop() {
    $.ajax({
        url: 'inc/shop.php',
        success: function(data) {
            $('#contentDiv').fadeOut(300, function(){
                $('#contentDiv').html(data);
                $('#contentDiv').fadeIn(400);
            });
        }
    });    
}

function showCategory(cID) {
    $.ajax({
        url: 'inc/shop.php?f=cat&cid='+cID,
        success: function(data) {
            $('#contentDiv').html(data);
        }
    });
}

function openPage(pID) {
    $.ajax({
        url: 'inc/pages.php?page='+pID,
        success: function(data) {
            $('#contentDiv').fadeOut(300, function(){
                $('#contentDiv').html(data);
                $('#contentDiv').fadeIn(400);
            });
        }
    });
}

function openNews(pID) {
    $.ajax({
        url: 'inc/pages.php?page=opennews&id='+pID,
        success: function(data) {
            $('#contentDiv').fadeOut(300, function(){
                $('#contentDiv').html(data);
                $('#contentDiv').fadeIn(400);
            });
        }
    });
}

function changePrice (fieldID, pID) {
	var valueline = $('#'+fieldID+'_'+pID+' :selected').val();
	var valueArray = valueline.split('#');
	if (valueArray[1]>0) { $('#price_'+pID).html("Hinta "+valueArray[1]+" &euro;&nbsp;&nbsp;<button type='button' onClick=\"addtoBasket("+pID+");\">Tilaa</button>"); }
}

function addtoBasket (pID) {
	var valueline1 = $('#koko_'+pID+' :selected').val();	
	var valueline2 = $('#vari_'+pID+' :selected').val();
	
	if(typeof(valueline1) != "undefined"){
		var valueArray = valueline1.split('#');
		value_id1 = valueArray[0];
	} else {
		value_id1 = 0;
	}

	if(typeof(valueline2) != "undefined"){
		var valueArray = valueline2.split('#');
		value_id2 = valueArray[0];
	} else {
		value_id2 = 0;
	}
	
	CB_Open('href=inc/shop_func.php?f=cart&f2=add&id='+pID+'&vl1='+value_id1+'&vl2='+value_id2+',,type=iframe,,height=400,,width=700');
}

function showImage (imagefile) {
	CB_Open('href='+imagefile+',,type=image,,height=400,,width=400');
}
