

function sortNumber(a, b)
{
return a - b;
}

function count_price(){
		sels = $$('#shop_options select');
		var obj_id = 'opt';		
		err = false;
		var arr_option = new Array();
		var i_el = 0;
		
			
		sels.each (function (val) {
			if(val.value!=0){
				arr_option[i_el] = val.value;
				i_el++;
			}
			else{
				err = true;
			}
		});
		
		var arr_sort_option = arr_option.sort(sortNumber);
		arr_sort_option.each (function (val) {
				obj_id+='_'+val;
		});
		
		if($chk($(obj_id))){
			$('price_last').innerHTML = (parseFloat($('price_last_def').value)+parseFloat($(obj_id).value)).toFixed(2);
			$('option_info').innerHTML = '';
			if($('price_old')){
				$('price_old').innerHTML = (parseFloat($('price_old_def').value)+parseFloat($(obj_id).value)).toFixed(2);
			}
		}
		else if(err){
			$('price_last').innerHTML = (parseFloat($('price_last_def').value)).toFixed(2);
			$('option_info').innerHTML = '';
			if($('price_old')){
				$('price_old').innerHTML = (parseFloat($('price_old_def').value)).toFixed(2);;
			}
			return;
		}
		else{
			$('option_info').innerHTML = nooptMsg;
		}
}

function addToBasket (id, quantity, countOpt)
{

	sels = $$('#shop_options select');
	optId = 'opt_id';
	err = false;
	var i_el = 0;
	var arr_option = new Array();
	
	sels.each (function (val) {
			if(val.value!=0){
				arr_option[i_el] = val.value;
				i_el++;
			}
			else{
				err = true;
			}
		});
		
	var arr_sort_option = arr_option.sort(sortNumber);
		
		arr_sort_option.each (function (val) {
				optId+='_'+val;
		});	
		
	if (err){
		alert(optMsg);
		return;
	}	

	if(!$(optId) && countOpt>0){
		alert(nooptMsg);
		return;
		}

	quantity = parseInt(quantity);
	
	url = domain + '/shop/?a=basket&action=add&id='+id+'&q='+quantity;
	if ($(optId)) {
        url += '&opt='+$(optId).value;
    }
	
	var myAjax = new Request({
		method: 'get', 
		url: url,
		onSuccess: ansBasket
	}).send();
	showPreloader();
}	

function ansBasket(res)
{
	hidePreloader();	
	ret = JSON.decode (res);
	if (ret['msg']) {
		alert (ret['msg']);
	}
	if (ret['success'] == 1) {
		$('simple_basket').innerHTML = ret['details'];
	}
}

function addToBasketFromCuby (id, c_id, quantity, optVal)
{

	url = domain + '/shop/?a=basket&action=add&id='+id+'&q='+quantity;
	if (optVal) {
        url += '&opt='+optVal;
    }
	var myAjax = new Request({
		method: 'get', 
		url: url,
		onSuccess: ansBasketOption
	}).send();
	showPreloader();
	removeFromCuby(c_id, 2);
}

function ansBasketOption(res)
{
	hidePreloader();	
	ret = JSON.decode (res);
	
	if (ret['msg']) {
		alert (ret['msg']);
	}
	if (ret['success'] == 1) {
		//window.location.reload();	
		//$('simple_basket').innerHTML = ret['details'];
		cubyBasket(1, 0);
	}
}

function addToComparator (id)
{
	url = domain + '/shop/?a=comparator&action=add&id='+id;
	var myAjax = new Request({
		method: 'get', 
		url: url,
		onSuccess: ansComparator
	}).send();
	showPreloader();
}	

function ansComparator(res)
{
	hidePreloader();	
	ret = JSON.decode (res);
	if (ret['msg']) {
		alert (ret['msg']);
	}
	if (ret['success'] == 1) {
		$('simple_comparator').innerHTML = ret['details'];
	}
}

function removeComparator (cfr, id) 
{
	if (confirm(cfr)) {
		var myAjax = new Request({
			method: 'get', 
			url: domain + '/shop/?a=comparator&action=remove&id=' + id,
			onSuccess: ansRemComparator
		}).send();
		showPreloader();		
	}
}

function ansRemComparator(res)
{
	hidePreloader();
	ret = JSON.decode (res);
	if (ret['msg']) {
		alert (ret['msg']);
	}
	if (ret['success'] == 1) {
		window.location.reload();
		$('simple_comparator').innerHTML = ret['details'];
	}
}

function change_pict(parent_id,ph_id){

	sels = $$('#'+parent_id+' img');
	sels.each (function (val) {
		val.style.display = 'none';
	});	
	$('main'+ph_id).style.display = '';
	$('currentPhoto').value = ph_id.replace('zoom_', '');
}

function change_color_pict(parent_id,ph_id){
	
	sels = $$('#'+parent_id+' img');
	sels.each (function (val) {
		val.style.display = 'none';
	});	
	if($('maincolorphoto_'+ph_id)){
		$('maincolorphoto_'+ph_id).style.display = '';
	}else{
		$('mainphoto_0').style.display = '';
	}	
	$('currentPhoto').value = 'colorphoto_'+ph_id;
}

function changePict_navi(val, allP){
	
	var nextP = parseInt($('currPhoto').value)+val;
	
	if(parseInt($('currPhoto').value)==5){
		$('mainzoom_photo_5').style.display = 'none';
		$('mainzoom_photo_0').style.display = '';
		$('currPhoto').value = 	0;
	}
	else if(nextP>=0 && nextP<=allP){
		$('mainzoom_photo_'+$('currPhoto').value).style.display = 'none';
		$('mainzoom_photo_'+nextP).style.display = '';
		$('currPhoto').value = 	nextP;
	}
	else if(nextP<0){
		nextP=allP;
		$('mainzoom_photo_'+$('currPhoto').value).style.display = 'none';
		$('mainzoom_photo_'+nextP).style.display = '';
		$('currPhoto').value = 	nextP;
	}
	else if(nextP>allP){
		nextP=0;
		$('mainzoom_photo_'+$('currPhoto').value).style.display = 'none';
		$('mainzoom_photo_'+nextP).style.display = '';
		$('currPhoto').value = 	nextP;
	}
}

function zoom_pict(){
	
	$('zoomBox').setStyle('height', mainH);
	$('zoomBox').setStyle('display', '');
	var zoomH = 870+200;
	if($('zoomNavi')){zoomH+=75;}
	if(zoomH > $('mainBox').offsetHeight){
		var mainH = zoomH+'px';		
	}else{
		var mainH = $('mainBox').offsetHeight+'px';
	}
	$('zoomBox').setStyle('height', mainH);

	$('prodZoom').setStyle('display', '');
	sels = $$('#zoom_main_photo img');
	sels.each (function (val) {
		val.style.display = 'none';
	});	
	$('mainzoom_'+$('currentPhoto').value).style.display = '';
}

function close_zoom_pict(){
		
	sels = $$('#main_photo img');
	sels.each (function (val) {
		val.style.display = 'none';
	});	
	$('main'+$('currentPhoto').value).style.display = '';
	$('prodZoom').setStyle('display', 'none');
	$('zoomBox').setStyle('display', 'none');
}

var objectsArray = new Array();

function addToArray(obj, pos1){
	objectsArray[pos1] = obj;
}

function pictureObject(p_main, p_zoom){
	this.p_main=p_main;
	this.p_zoom=p_zoom;
}

