function goTo (page) {

	if (page != "" ) {
		document.location.href = page;
	}
	return false;
}

function copyData( id ) {
	if ( id == "billing" ) { 
		$('#szamlaDiv').find('input').each( function() {
			if ( $(this).attr('name') != 'billing_szemelyes' ) {
				$(this).val($('[name="'+( $(this).attr('name').replace(''+id+'_', '') )+'"]').val());
			}	
		});	
	}
	else if ( id == "deliver" ) {
		var answer = confirm("Ugyanazok mint a számlázási adatok?"); {
			if (answer){
				$('#szallitasadatok').find('input').each( function() {
					if ( $(this).attr('name') != 'deliver_type' ) {
						$(this).val($('[name="'+( $(this).attr('name').replace(''+id+'_', 'billing_') )+'"]').val());
					}
				});
				if ( $('input[name="deliver_email"]').val() == '' && $('input[name="email"]').val() != '' ) {
					$('input[name="deliver_email"]').val($('input[name="email"]').val());
				}
				if ( $('input[name="deliver_email"]').val() == '' && $('input[name="ownemail"]').val() != '' ) {
					$('input[name="deliver_email"]').val($('input[name="ownemail"]').val());
				}
				if ( $('input[name="deliver_email"]').val() == '' && $('input[name="checkemail"]').val() != '' ) {
					$('input[name="deliver_email"]').val($('input[name="checkemail"]').val()); 
				}
			}
		}
	}
}

function addMainMessage(text, error) {
	classN = 'errorSucc';
	if (error) classN = 'errorMess';
	mBox = $("#messageBox");
	if ( mBox.css('display') == 'none' ) {
		offLeft = $(".quickCartP").offset().left;
		$("#messageBox p").remove();
		$("#messageBox span:first").before("<p>"+text+"</p>");
		mBox.fadeIn("fast").delay(3000).fadeOut("fast");
		}
}

function setErrorLogs(obj) {
	$('.comm').html('');
	if ( obj.rettype == 'error' ) {
		if (obj.params) {
			for( i in obj.params ) { $('[name="'+i+'"]').parent().next('.comm').html(obj.params[i]); }
		} else if (obj.message) {
			addMainMessage(obj.message, 1);
		}
	} else if ( obj.rettype == 'succ' ) {
		if (obj.page) { goTo(obj.page); }
		else if (obj.message) {
			addMainMessage(obj.message, 0);
		}
	}
}

function setLoginText(obj) {
	if (obj.type == 'loggdin') {
		if ( obj.text ) goTo(obj.text);
		else history.go(0);
	} else { alert(obj.text); }
}


function priceBg(className, spanClass) {
	if (!className) return false;
	if (!spanClass) spanClass = className;
	$('.'+className).html(function() {
		return '<span class="'+spanClass+'l"></span><span class="'+spanClass+'c">'+$(this).html()+'</span><span class="'+spanClass+'r"></span>';
	});
}

function getGroup() { 
}

function getGroupData(sku, key) {
	sku2 = sku.replace('-','_');
	return eval('productGroupData.'+sku2+'.'+key)
}

function setGroupData(sku, key, value) {
	eval('productGroupData.'+sku+'.'+key+' = "'+value+'"')
}

var productGroupData = null;
function changeProductGroup(obj) {
	newSku = obj.val();
	$('input[name="product_sku"]').val(newSku);
	$('select[name="count"] option')[getGroupData(newSku,'cart_count')].selected ='selected';
	
	$('div.product_price').html(getGroupData(newSku,'details_pricelist'));
	priceBg('product_pricePrice', 'price');

	imageP = getGroupData(newSku,'product_image');
	$('p.product_image a').attr('href', imageP.path);
	$('p.product_image img').attr('src', imageP.thumb);
}

function transit_hide(){
	$("#dt2, #dt22").click(function(){
		$(".transitCost").hide();
		$(".szemelyesen").show();
		$(".futarral").hide();
	});

	$("#dt1, #dt11").click(function(){
		$(".transitCost").show();
		$(".szemelyesen").hide();
		$(".futarral").show();
	});
}

function ajaxform(){
		$("form.addToCart, .formClass, form.addToFav, form.delfav").bind("submit", function(){
			retText = '&time='+ new Date().getTime();
			$.post(
				$(this)[0].action+retText,
				$(this).serialize(),
				function(responseText) {
					if ( responseText ) {
						resObj = eval(responseText);
						if (resObj.mod == 'cart') setCartText(resObj, resObj.html);
						if (resObj.mod == 'login') setLoginText(resObj);
						if (resObj.mod == 'fav') setFavText(resObj, resObj.html);
						//if ( $(".product_detailsDiv").length ) { getGroup(); }
					
					}
				}
			);

			return false;
	});
}

function megjelen(r){
	$('.feher, .zold').show(); 
	$('.adatlap').hide('slow');
	$('.main_'+r).hide('slow');
	$('.datas_'+r).show('slow');

}

function bezar(r){

	$('.main_'+r).show('slow');
	$('.datas_'+r).hide('slow');
	
}

$(document).ready(function() {
	$(".iveskeret").html(function() {
		$(this).css('position', 'relative');
		return $(this).html()+'<span class="ltimg"></span><span class="rtimg"></span><span class="lbimg"></span><span class="rbimg"></span>';
	});

	priceBg('gomb');
	
	priceBg('gomb2');
	
	ajaxform();
	
	//transit_hide();
	/*
	$(".search_input").autocomplete( '?l1=search&l2=plug_search&l3=main', { minChars: 2 });
	*/
		$("a.gomb2").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'fade',
		'speedIn'		:	600,
		'speedOut'		:	200,

		'onComplete'	:	function(){
				
		},
		'hideOnOverlayClick' : false,
		'hideOnContentClick': false
	});
	
	$(".szemelyesen").hide();
	
	$('.mainMessage').show("slow");

	priceBg('product_pricePrice', 'price');

	$('.groupsel').change(function() { changeProductGroup($(this)); });

	$("#center").css('min-height', $("#leftCont").css("height"));
	
	$('span #submitLP').click(function(){ $('lost_password').submit(); });
		
	$('.opacity60').hover(function(){
	$(this).fadeTo('fast', 0.33);
	});
	
	$('.opacity60').mouseleave(function(){
	$(this).fadeTo('fast', 1);
	});
	
	$('.fav_det').mouseover(function(){
	
		$('.close_span', this).show();
	});
	
	$('.fav_det').mouseleave(function(){
	
		$('.close_span').hide();
	});
	
	idozito();
});

function idozito() {
//	var portfolioi=1;
	$('ul#portfolio').innerfade({
		
						speed: 500,
						timeout: 3000,
						type: 'sequence',
						containerheight: '468px'
					});
//portfolioi++;
//	if(portfolioi <= 4){
//	setTimeout("idozito()",600);
//	}
//	idozito();
}

