function SliderChange(e, ui){
	act_slider = 1;
	var maxScroll = $("#prod_box_wrap").width() - $("#prod_box_holder").width() + 15;
	if (maxScroll>0) maxScroll = 0;
	var left_pos = ui.value * (maxScroll / 100);
	$("#prod_box_holder").css({left: left_pos});
	var found = 0;
	var spos = 0;
	$("#prod_box_holder div.prod_box:visible").map(function(){
		var pos = $("#prod_box_holder").position().left+$(this).position().left+5;
		if (pos>0 && found==0){
			spos = $(this).position().left;
			found = 1;
		}
	});
	if (found==1){
		$("#prod_box_holder").animate({"left":-spos},function(){
			act_slider = 0;
		});		
	}
}

function SliderSlide(e, ui){
	act_slider = 1;
	var maxScroll = $("#prod_box_wrap").width() - $("#prod_box_holder").width() + 15;
	if (maxScroll>0) maxScroll = 0;
	var left_pos = ui.value * (maxScroll / 100);
	$("#prod_box_holder").css({left: left_pos});
	act_slider = 0;
}

function SliderChangeArticles(e, ui){
	act_slider = 1;
	var maxScroll = $("#articles_box_wrap").width() - $("#articles_box_holder").width() + 15;
	if (maxScroll>0) maxScroll = 0;
	var left_pos = ui.value * (maxScroll / 100);
	$("#articles_box_holder").css({left: left_pos});
	var found = 0;
	var spos = 0;
	$("#articles_box_holder div.article_box:visible").map(function(){
		var pos = $("#articles_box_holder").position().left+$(this).position().left;
		if (pos>0 && found==0 && $("#articles_box_holder").position().left!=0){
			spos = $(this).position().left;
			found = 1;
		}
	});
	if (found==1){
		$("#articles_box_holder").animate({"left":-spos},function(){
			act_slider = 0;
		});		
	}}

function SliderSlideArticles(e, ui){
	act_slider = 1;
	var maxScroll = $("#articles_box_wrap").width() - $("#articles_box_holder").width() + 15;
	if (maxScroll>0) maxScroll = 0;
	var left_pos = ui.value * (maxScroll / 100);
	$("#articles_box_holder").css({left: left_pos});
	act_slider = 0;
}

var act_slider = 0;
var is_action = 0;
var is_promo_prod = 0;
var is_promo_promo = 0;
var is_misc_b = 0;
var is_misc_w = 0;
var nav_sel = 0;
var nav_sel_row = 1;
var nav_sel_col = 1;
var is_overlay = 0;
var prod_loading = 0;
var prod_img = 0;

var pp_items = 1;
var pp_item = 1;

var is_buy = 0;

function nav_sel_first(){
	var sel_box = 'm_'+nav_sel_row+'_'+nav_sel_col;
	if ($('#'+sel_box).length>0){
		$('#'+sel_box).addClass('prod_box_sel');
		nav_sel = 1;	
	}
	
}

function nav_sel_left(){
	var selected_box = 'm_'+nav_sel_row+'_'+nav_sel_col;
	var col = parseInt(nav_sel_col)-1
	var row = nav_sel_row
	sel_box = 'm_'+row+'_'+col;
	if ($('#'+sel_box).length>0){
		if ($('#'+selected_box).hasClass('prod_box_sel')) $('#'+selected_box).removeClass('prod_box_sel')
		$('#'+sel_box).addClass('prod_box_sel');
		nav_sel_row = row;
		nav_sel_col = col;
		nav_sel = 1;	
	}	
}

function nav_sel_right(){
	var selected_box = 'm_'+nav_sel_row+'_'+nav_sel_col;
	var col = parseInt(nav_sel_col)+1
	var row = nav_sel_row
	sel_box = 'm_'+row+'_'+col;
	if ($('#'+sel_box).length>0){
		if ($('#'+selected_box).hasClass('prod_box_sel')) $('#'+selected_box).removeClass('prod_box_sel')
		$('#'+sel_box).addClass('prod_box_sel');
		nav_sel_row = row;
		nav_sel_col = col;
		nav_sel = 1;	
	}	
}

function nav_sel_up(){
	var selected_box = 'm_'+nav_sel_row+'_'+nav_sel_col;
	var col = nav_sel_col
	var row = parseInt(nav_sel_row)-1
	sel_box = 'm_'+row+'_'+col;
	if ($('#'+sel_box).length>0){
		if ($('#'+selected_box).hasClass('prod_box_sel')) $('#'+selected_box).removeClass('prod_box_sel')

		var offset_top = $('#'+sel_box).offset().top;
		var wh = $(window).height();
		var scroll_top = $(window).scrollTop();
		if (offset_top>(wh-scroll_top)){
			$(window).scrollTop(scroll_top-wh);
		}
		$('#'+sel_box).addClass('prod_box_sel');
		nav_sel_row = row;
		nav_sel_col = col;
		nav_sel = 1;	
	}	
}

function nav_sel_down(){
	var selected_box = 'm_'+nav_sel_row+'_'+nav_sel_col;
	var col = nav_sel_col
	var row = parseInt(nav_sel_row)+1
	sel_box = 'm_'+row+'_'+col;
	if ($('#'+sel_box).length>0){
		if ($('#'+selected_box).hasClass('prod_box_sel')) $('#'+selected_box).removeClass('prod_box_sel')
		
		var offset_top = $('#'+sel_box).offset().top;
		var wh = $(window).height();
		var scroll_top = $(window).scrollTop();
		if (offset_top>(wh+scroll_top)){
			$(window).scrollTop(scroll_top+wh);
		}
		$('#'+sel_box).addClass('prod_box_sel');
		nav_sel_row = row;
		nav_sel_col = col;
		nav_sel = 1;	
	}	
}

$(document).keyup(function(event){
    if (event.keyCode == 27) { // escape
    	if ($('div.overlay').length>0){ 
    		$('div.overlay').hide().remove();
    		if ($('div.clipboard').length>0){
    			$('div.clipboard').remove();
    		}
    		is_overlay = 0;
    	}
    }
});

function load_keyboard_nav(){
	$(document).keyup(function(event){
	    if ($('#shop').length>0){
		    if (event.keyCode == 32) { // space
		    	if (nav_sel==1 && is_overlay==0){
					var sel_box = 'm_'+nav_sel_row+'_'+nav_sel_col;
		    		$('#'+sel_box+' div.prod_info a').trigger('click');
			    }
		    	if (nav_sel==1 && is_overlay==1){
					$('div.overlay').hide().remove();
					is_overlay=0;
			    }
		    }
		    if (event.keyCode == 37) { // left
		    	if (nav_sel==1 && is_overlay==0){
		    		nav_sel_left();
		    	}
		    }
		    if (event.keyCode == 39) { // right
		    	if (nav_sel==1 && is_overlay==0){
		    		nav_sel_right();
		    	}
		    }
		    if (event.keyCode == 38) { // up
		    	if (nav_sel==1 && is_overlay==0){
		    		nav_sel_up();
		    	}
		    }
		    if (event.keyCode == 40) { // down
		    	if (is_overlay==0){
			    	if (nav_sel==1){
			    		nav_sel_down();
				    }
				    else{
				    	nav_sel_first();
				    }
				}
		    }
		}
	});
	$(document).keydown(function(event){
	    if ($('#shop').length>0){
		    if (event.keyCode == 32) { // space
		    	if (nav_sel==1){
			    	return false;
			    }
		    }
		    if (event.keyCode == 37) { // left
		    	return false;
		    }
		    if (event.keyCode == 38) { // up
		    	return false;
		    }
		    if (event.keyCode == 39) { // right
		    	return false;
		    }
		    if (event.keyCode == 40) { // down
		    	return false;
		    }
		}
	});
}

function load_products(type,page){
	prod_loading = 1;
	var ipr = $('#shop_content').width()/192;
	
	var cs_sq = $('input#cs_sq').val();
	var cs_filter = $('input#cs_filter').val();
	var cs_brand = $('input#cs_brand').val();
	var cs_gender = $('input#cs_gender').val();
	var cs_categ = $('input#cs_categ').val();
	var cs_scateg = $('input#cs_scateg').val();
	var cs_type = $('input#cs_type').val();
	var cs_sort = $('input#cs_sort').val();
	var cs_sortt = $('input#cs_sortt').val();
	var cs_sortd = $('input#cs_sortd').val();

	var cs_page = ($('input#cs_page').length>0?$('input#cs_page').val():1);
	if (page!=0){
		cs_page = page;
		$('input#cs_page').val(cs_page);
	}
	
	var csf_brand = $('input#csf_brand').val();
	var csf_size = $('input#csf_size').val();
	var csf_price = $('input#csf_price').val();
	var csf_color = $('input#csf_color').val();
	var csf_rating = $('input#csf_rating').val();
	var vars = {ipr:ipr,p:cs_page,cs_sq:cs_sq,cs_filter:cs_filter,cs_brand:cs_brand,cs_gender:cs_gender,cs_categ:cs_categ,cs_scateg:cs_scateg,cs_type:cs_type,cs_sort:cs_sort,cs_sortt:cs_sortt,cs_sortd:cs_sortd,csf_brand:csf_brand,csf_size:csf_size,csf_price:csf_price,csf_color:csf_color,csf_rating:csf_rating};
	if (type==0){
		$('#shop_content').addClass('loader');
		$('#shop_icontent').load('scripts/get_products.php',vars,function(){
			load_keyboard_nav();
			$('#shop_content').removeClass('loader');
			$('#shop_icontent').show();
			prod_loading = 0;
		});
	}
	else{
		$.post('scripts/get_products.php',vars,function(data){
			$('#shop_load').fadeOut(function(){
				$(this).remove();
				$('#shop_icontent').append(data);			
				prod_loading = 0;
			});
		});
	}

}

function show_register(step){
	$('#cube_rict_content').addClass('loader');
	$('#cube_rict_contenth').fadeOut(function(){
		var top_pos = (step*355)-355;
		if (top_pos>0) top_pos = -top_pos;
		var h1c = '<em>Cont nou</em> / Date personale / Termeni si conditii';
		if (step==1){
			h1c = '<em>Cont nou</em> / Date personale / Termeni si conditii';
			if ($('#cube_ric_bottom a.ricbl').length>0) $('#cube_ric_bottom a.ricbl').remove();
			$('#cube_ric_bottom a.ricbr').attr('id','cube_register_1');
			$('#cube_ric_bottom a.ricbr').html('Continua');
			$('#cube_ric_bottom a.ricbr').removeClass('sel');
			$('#cube_ric_bottom a.ricbr').removeClass('nbg');
			$('input#user_code').val('');
			$('#code img').attr('src','scripts/get_code.php?k='+Math.random());
			$('input#validate_step_1').val('0');
		}
		if (step==2){
			h1c = 'Cont nou / <em>Date personale</em> / Termeni si conditii';
			if ($('#cube_ric_bottom a.ricbl').length>0){
				$('#cube_ric_bottom a.ricbl').attr('id','show_1');
			}
			else{
				$('#cube_ric_bottom').append('<a href="#" class="ricbl" id="show_1">Inapoi</a>');			
			}
			$('#cube_ric_bottom a.ricbr').attr('id','cube_register_2');
			$('#cube_ric_bottom a.ricbr').html('Continua');
			$('#cube_ric_bottom a.ricbr').addClass('sel');
			$('#cube_ric_bottom a.ricbr').removeClass('nbg');
			$('input#validate_step_2').val('0');
		}
		if (step==3){
			h1c = 'Cont nou / Date personale / <em>Termeni si conditii</em>';
			$('#cube_ric_bottom a.ricbl').attr('id','show_2');
			$('#cube_ric_bottom a.ricbr').attr('id','cube_register_3');
			$('#cube_ric_bottom a.ricbr').html('Sunt de acord, vreau cont!');
			$('#cube_ric_bottom a.ricbr').addClass('sel');
			$('#cube_ric_bottom a.ricbr').addClass('nbg');

			
		}
		$('#cube_ric_top h1').html(h1c);
		$('#cube_rict_contenth').css('top',top_pos+'px');
		$('#cube_rict_content').removeClass('loader');

		$('#cube_rict_contenth').fadeIn(function(){
			$('#cube_rict_terms').jScrollPane({
				scrollbarWidth:20,
				dragMinHeight:120,
				dragMaxHeight:120
			});			
		});		
	});
}

function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}

function isValidPhone(value){
	return /^(\(?\+?[0-9]*\)?)?[0-9_\- \(\)]*$/.test(value);
}

function trim(str) {
	var	str = str.replace(/^\s\s*/, ''),
		ws = /\s/,
		i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);
}

function check_password(){
	var password = trim($('input#user_password').val());
	var password1 = trim($('input#user_password1').val());
	if (password!='' && password1!='' && password==password1){
		$('input#user_password1').parent('div').addClass('conf');
	}
	else{
		$('input#user_password1').parent('div').removeClass('conf');	
	}
}

function next_pp(){
	var page = (pp_item+1<=pp_items)?pp_item+1:1;
	var my_link = $('#pp'+page);
	var step = 401;
	var action_step = 0;
	if (is_action==0){
		is_action = 1;
		action_step = step*(page-1);
		$('#pp_box_holder').animate({left:'-'+action_step},300,function(){
			$('#ppn_content ul li a').filter(".sel").removeClass("sel");
			my_link.addClass("sel");
			pp_item = page;
			is_action = 0;
		});
		
	}
	return false;

}

function start_autoplay(){
	stop_autoplay();
	timerID = setInterval("next_pp();",5000);
}

function stop_autoplay(){
	if(typeof(timerID) !== 'undefined'){
		clearInterval(timerID);
	}
}

function show_checkout(step,type,address_type){
	if (type === undefined ) {
	      type = 0;
	}
	if (address_type === undefined ) {
	      address_type = -1;
	}

   	var auth = $('#cube_chk_step1').attr('class').replace('auth_','');
	var extra_info = '';
	if (auth==0){
		extra_info = ' / Login sau Creare Cont'
	}
	var header = '<em>Cos</em>'+extra_info+' / Adresa Livrarii / Casa / Plata &amp; Livrarea / Finalizarea';
	switch(step){
		case 1:{
			header = '<em>Cos</em>'+extra_info+' / Adresa Livrarii / Casa / Plata &amp; Livrarea / Finalizarea';
			break;
		}
		case 2:{
			header = 'Cos / <em>Login sau Creare Cont</em> / Adresa Livrarii / Casa / Plata &amp; Livrarea / Finalizarea';
			break;
		}
		case 3:{
			header = 'Cos'+extra_info+' / <em>Adresa Livrarii</em> / Casa / Plata &amp; Livrarea / Finalizarea';
			break;
		}
		case 4:{
			header = 'Cos'+extra_info+' / <em>Adresa Livrarii</em> / Casa / Plata &amp; Livrarea / Finalizarea';
			break;
		}
		case 5:{
			header = 'Cos'+extra_info+' / Adresa Livrarii / <em>Casa</em> / Plata &amp; Livrarea / Finalizarea';
			break;
		}
		case 6:{
			header = 'Cos'+extra_info+' / Adresa Livrarii / Casa / <em>Plata &amp; Livrarea</em> / Finalizarea';
			break;
		}
		case 7:{
			header = 'Cos'+extra_info+' / Adresa Livrarii / Casa / Plata &amp; Livrarea / <em>Finalizarea</em>';
			break;
		}
	}
	var loader_height = $('#cube_chks'+step+'_content').css('height').replace('px','');
	$('#cube_chk_contenth').fadeOut();
	$('#cube_chk_loader').css({'height':loader_height+'px'});
	$('#cube_chk_loader').fadeIn(function(){
		if (type==1){
			$('#cube_chk_contenth').load('include/cube_checkoutc.inc.php',function(){
				if (address_type==0 || address_type==1){
					$('#address_type'+address_type).attr('checked',1);
					$('#cship_name').html($('input#user_fname').val()+' '+$('input#user_lname').val());
					$('#cship_phone').html($('input#user_phone').val());
					if (address_type==1){
						$('#cship_address').html($('textarea#cinfo_address').val());	
						$('#cship_city').html($('input#cinfo_city').val());
						$('#cship_state').html($('input#cinfo_state').val());
						$('#cship_zip').html($('input#cinfo_zip').val());
						
						$('#ship_address').val($('textarea#cinfo_address').val());
						$('#ship_city').val($('input#cinfo_city').val());
						$('#ship_state').val($('input#cinfo_state').val());
						$('#ship_zip').val($('input#cinfo_zip').val());
						
					}
					else{
						$('#cship_address').html($('textarea#user_address').val());	
						$('#cship_city').html($('input#user_city').val());
						$('#cship_state').html($('input#user_state').val());
						$('#cship_zip').html($('input#user_zip').val());				

						$('#ship_address').val($('textarea#user_address').val());
						$('#ship_city').val($('input#user_city').val());
						$('#ship_state').val($('input#user_state').val());
						$('#ship_zip').val($('input#user_zip').val());
					}				
				}
				$('#cube_checkout_icontent h1').html(header);
				var top_pos = 485*step-485;
				$('#cube_chk_contenth').css({'top':-top_pos+'px'});		
				$('#cube_chk_loader').fadeOut();
				$('#cube_chk_contenth').fadeIn();
				if (step==1){
					$('#cube_chks1c_contenth').jScrollPane({
						scrollbarWidth:20,
						dragMinHeight:120,
						dragMaxHeight:120
					});		
				}			
			});
		}
		else{
			$('#cube_checkout_icontent h1').html(header);
			var top_pos = 485*step-485;
			$('#cube_chk_contenth').css({'top':-top_pos+'px'});		
			$('#cube_chk_loader').fadeOut();
			$('#cube_chk_contenth').fadeIn();
			if (step==1){
				$('#cube_chks1c_contenth').jScrollPane({
					scrollbarWidth:20,
					dragMinHeight:120,
					dragMaxHeight:120
				});		
			}
		}
	});
}

$(document).ready(function(){
	// register form

	$('#get_zipcode').live('click',function(){
		window.open('http://www.posta-romana.ro/postal_codes?moo_cp_location='+$('input#user_city').val()+'&moo_cp_street='+$('textarea#user_address').val());
		return false;
	});

	$('#get_zipcodec').live('click',function(){
		window.open('http://www.posta-romana.ro/postal_codes?moo_cp_location='+$('input#cinfo_city').val()+'&moo_cp_street='+$('textarea#cinfo_address').val());
		return false;
	});

	$('#cube_ric_bottom a.ricbl').live('click',function(){
		var my_id = $(this).attr('id').replace('show_','');
		show_register(my_id);
		return false;
	});

	$('#cube_register_1').live('click',function(){
		var error = 0;
		var validate = 0;
		$('#form_register_1 p.err').html('');
		if ($('input#user_account').parent('div').hasClass('err')) $('input#user_account').parent('div').removeClass('err');
		if ($('input#user_email').parent('div').hasClass('err')) $('input#user_email').parent('div').removeClass('err');
		if ($('input#user_password').parent('div').hasClass('err')) $('input#user_password').parent('div').removeClass('err');
		if ($('input#user_password1').parent('div').hasClass('err')) $('input#user_password1').parent('div').removeClass('err');
		if ($('input#user_code').parent('div').hasClass('errl')) $('input#user_code').parent('div').removeClass('errl');
		if (trim($('input#user_account').val())==''){
			$('input#user_account').parent('div').addClass('err');
			error = 1;
		}
		if (!isValidEmailAddress(trim($('input#user_email').val()))){
			$('input#user_email').parent('div').addClass('err');
			error = 1;
		}
		if (trim($('input#user_password').val())==''){
			$('input#user_password').parent('div').addClass('err');
			error = 1;
		}
		if (trim($('input#user_password1').val())==''){
			$('input#user_password1').parent('div').addClass('err');
			error = 1;
		}
		if (trim($('input#user_code').val())==''){
			$('input#user_code').parent('div').addClass('errl');
			error = 1;
		}
		if (error==1){
			$('#form_register_1 p.err').html('*Toate campurile trebuie completate pentru a trece la pasul urmator.');
		}
		else{
			var validate = trim($('input#user_account').val());
			$.post('scripts/get_validation.php',{type:0,validate:encodeURIComponent(validate)},function(data){
				if (data==1){
					validate = trim($('input#user_email').val());
					$.post('scripts/get_validation.php',{type:1,validate:encodeURIComponent(validate)},function(data){
						if (data==1){
							validate = trim($('input#user_code').val());
							$.post('scripts/get_validation.php',{type:2,validate:encodeURIComponent(validate)},function(data){
								if (data==1){
									$('input#validate_step_1').val('1');
									show_register(2);
								}
								else{
									$('#form_register_1 p.err').html('*Codul introdus este gresit!');
									$('input#user_code').parent('div').addClass('errl');
									$('input#user_code').val('');
									$('#code img').attr('src','scripts/get_code.php?k='+Math.random());
								}
							});						
						}
						else{
							$('#form_register_1 p.err').html('*Adresa de e-mail este deja inregistrata!');
							$('input#user_email').parent('div').addClass('err');
						}
					});
				
				}
				else{
					$('#form_register_1 p.err').html('*Username-ul ales exista deja!');
					$('input#user_account').parent('div').addClass('err');
				}
			});
		}
		return false;
	});

	$('#cube_register_2').live('click',function(){
		var error = 0;
		var validate = 0;
		$('#form_register_2 p.err').html('');
		if ($('input#user_fname').parent('div').hasClass('err')) $('input#user_fname').parent('div').removeClass('err');
		if ($('input#user_lname').parent('div').hasClass('err')) $('input#user_lname').parent('div').removeClass('err');
		if ($('select#user_gender').parent('div').hasClass('err')) $('select#user_gender').parent('div').removeClass('err');
		if ($('select#user_bday').parent('div').hasClass('err')) $('select#user_bday').parent('div').removeClass('err');
		if ($('select#user_bmonth').parent('div').hasClass('err')) $('select#user_bmonth').parent('div').removeClass('err');
		if ($('select#user_byear').parent('div').hasClass('err')) $('select#user_byear').parent('div').removeClass('err');
		if ($('textarea#user_address').parent('div').hasClass('err')) $('textarea#user_address').parent('div').removeClass('err');
		if ($('input#user_city').parent('div').hasClass('err')) $('input#user_city').parent('div').removeClass('err');
		if ($('input#user_state').parent('div').hasClass('err')) $('input#user_state').parent('div').removeClass('err');
		if ($('input#user_zip').parent('div').hasClass('err')) $('input#user_zip').parent('div').removeClass('err');
		if ($('input#user_phone').parent('div').hasClass('err')) $('input#user_phone').parent('div').removeClass('err');

		if (trim($('input#user_fname').val())==''){
			$('input#user_fname').parent('div').addClass('err');
			error = 1;
		}
		if (trim($('input#user_lname').val())==''){
			$('input#user_lname').parent('div').addClass('err');
			error = 1;
		}
		if (trim($('select#user_gender').val())==''){
			$('select#user_gender').parent('div').addClass('err');
			error = 1;
		}
		if (trim($('select#user_bday').val())==''){
			$('select#user_bday').parent('div').addClass('err');
			error = 1;
		}
		if (trim($('select#user_bmonth').val())==''){
			$('select#user_bmonth').parent('div').addClass('err');
			error = 1;
		}
		if (trim($('select#user_byear').val())==''){
			$('select#user_byear').parent('div').addClass('err');
			error = 1;
		}
		if (trim($('textarea#user_address').val())==''){
			$('textarea#user_address').parent('div').addClass('err');
			error = 1;
		}
		if (trim($('input#user_city').val())==''){
			$('input#user_city').parent('div').addClass('err');
			error = 1;
		}
		if (trim($('input#user_state').val())==''){
			$('input#user_state').parent('div').addClass('err');
			error = 1;
		}
		if (trim($('input#user_zip').val())==''){
			$('input#user_zip').parent('div').addClass('err');
			error = 1;
		}
		if (!isValidPhone(trim($('input#user_phone').val())) || trim($('input#user_phone').val())==''){
			$('input#user_phone').parent('div').addClass('err');
			error = 1;
		}
		if (error==1){
			$('#form_register_2 p.err').html('*Toate campurile trebuie completate pentru a trece la pasul urmator.');
		}
		else{
			$('input#validate_step_2').val('1');
			show_register(3);
		}
		return false;
	});

	$('#cube_register_3').live('click',function(){
		if ($('input#validate_step_1').val()==1 && $('input#validate_step_1').val()==1){
			$('#cube_ric_bottom a').hide();
			$('#cube_rict_content').addClass('loader');
			$('#cube_rict_contenth').fadeOut(function(){		
				var inputs = [];
				$(':input', $('#form_register')).each(function() {
					inputs.push(this.name + '=' + encodeURIComponent(trim(this.value)));
				})
				jQuery.ajax({
					data: inputs.join('&'),
					url: $('#form_register').attr('action'),
					timeout: 10000,
					type: 'post',
					error: function() {
						alert('Ne pare rau dar inregistrarea nu se poate face momentan.\nVa rugam incercati mai tarziu.');
					},
					success: function(r) { 
						switch(r){
							case "1":
								document.location.href='';
								break;
							case "2": // acc
								$('#form_register_1 p.err').html('*Username-ul ales exista deja!');
								$('input#user_account').parent('div').addClass('err');
								$('input#validate_step_1').val('0');
								$('input#user_code').val('');
								$('#code img').attr('src','scripts/get_code.php?k='+Math.random());
								show_register(1);
								$('#cube_ric_bottom a').show();
								break;
							case "3": // email
								$('#form_register_1 p.err').html('*Adresa de e-mail este deja inregistrata!');
								$('input#user_email').parent('div').addClass('err');
								$('input#validate_step_1').val('0');
								$('input#user_code').val('');
								$('#code img').attr('src','scripts/get_code.php?k='+Math.random());
								show_register(1);
								$('#cube_ric_bottom a').show();
								break;
							case "4": // both
								$('#form_register_1 p.err').html('*Username-ul ales si adresa de e-mail este deja inregistrata!');
								$('input#user_account').parent('div').addClass('err');
								$('input#user_email').parent('div').addClass('err');
								$('input#validate_step_1').val('0');
								$('input#user_code').val('');
								$('#code img').attr('src','scripts/get_code.php?k='+Math.random());
								show_register(1);
								$('#cube_ric_bottom a').show();
								break;
							default:
								$('#cube_rict_content').removeClass('loader');
								$('#cube_rict_contenth').fadeIn();
								$('#cube_ric_bottom a').show();
								alert('Ne pare rau dar inregistrarea nu se poate face momentan.\nVa rugam incercati mai tarziu.');
								break;
						}
					}
				});
			});
		}
		else{
			alert('Ne pare rau dar inregistrarea nu se poate face momentan.\nVa rugam incercati mai tarziu.');
		}
		return false;
	});

	$('#form_register').submit(function(){
		return false;
	})

	$('#code_new').live('click',function(){
		$('#code img').attr('src','scripts/get_code.php?k='+Math.random());	
		return false;
	});

	// TOOL TIP BRANDS

	$('#smenu_brands li a, div.misc_b_box ul li a').live('mouseover',function(){
		$(this).children('strong.tt').clone().appendTo('body').attr('id','btt');
		$('#btt').show();
		var pos_x = 0;
		var pos_y = 0;
		var btt_h = $('#btt').outerHeight();
		$(this).mousemove(function(e){
			pos_x = e.pageX;
			pos_y = e.pageY-btt_h-5;
			$('#btt').css({'top':(pos_y)+'px','left':(pos_x)+'px'});
		});

	});

	$('#smenu_brands li a, div.misc_b_box ul li a').live('mouseout',function(){
		$('#btt').hide().remove();
	
	});
	
	


	// RESIZE SHOP
	
	if ($('#shop_holder').length>0){
		var ww = $(window).width();
		var sw = $.getScrollbarWidth()

		var sh_width = 960;
		if (ww>960){
			sh_width = Math.floor((ww-sw)/192)*192;
		}
		$('#shop').css('min-width',(sh_width-15)+'px');
		$('#wrap').css('min-width',(sh_width)+'px');
		$('#header').css('min-width',(sh_width)+'px');
		$('#shop_holder').css('width',(sh_width-15)+'px');
		$('#shop_content').css('width',(sh_width)+'px');

		load_products(0,0);
	}

	// PROD
	
	$('#cube_pic_zoom').live('mouseover',function(){
		$('#cube_pic_xlg').show();
		var pos_x = 0;
		var pos_y = 0;
		var offset = $('#cube_pic_zoom').offset();
		$('#cube_pic_zoom').mousemove(function(e){
			pos_x = e.pageX-offset.left;
			pos_y = e.pageY-offset.top;
			new_top = 0 - (pos_y/340 * (1000-340));
			new_left = 0 - (pos_x/740 * (1000-740));
			$('#cube_pic_xlg').css({'top':(new_top)+'px','left':(new_left)+'px'});
		});
	});

	$('#cube_pic_zoom').live('mouseout',function(){
		$('#cube_pic_xlg').hide();			
	});

	$('#cube_pictlr_zoom').live('click',function(){
		if (prod_img==0){
			prod_img = 1;
			var my_imgu = $(this).attr('href').split('#');
			var my_img = my_imgu[1];

			$('#cube_pic_zoom img.zoom').remove();
			if ($('#cube_pic_xlg').length>0) $('#cube_pic_xlg').remove();
			
			$('#cube_pic_zoom').fadeIn(function(){
				var img_src = 'images/products/'+my_img;
				var img_id = (my_img.replace('_zm.jpg','_xlg.jpg'));
				var img_zm = new Image();
				$(img_zm).load(function () {
					var img1 = $(this);
		
					var img_xlg_src = 'images/products/'+(my_img.replace('_zm.jpg','_xlg.jpg'));
		
					var img_xlg = new Image();
					$(img_xlg).load(function () {
						var img2 = $(this);
						img1.hide();
						img2.hide();
						$('#cube_pic_zoom').removeClass('loader');
						$('#cube_pic_zoom').append(img1);
						img1.fadeIn(function(){
							$('#cube_pic_zoom').append('<div id="cube_pic_xlg"></div>');		
							$('#cube_pic_xlg').append(img2);
							img2.show();
							prod_img = 0;						
						});		
					}).error(function () {
						alert('Error: Image could not be loaded.');
						prod_img = 0;
			    	}).attr({
			        	src: img_xlg_src
					});						
				}).error(function () {
					alert('Error: Image could not be loaded.');
					prod_img = 0;
		    	}).attr({
		        	src: img_src,
		        	id: img_id,
		        	'class': 'zoom'
				});			
			});

		}
		return false;
	});

	$('#cube_pic_zoom_close').live('click',function(){
		prod_img=1;
		$('#cube_pic_zoom').fadeOut(function(){
			if ($('#cube_pic_xlg').length>0) $('#cube_pic_xlg').remove();
			if ($('#cube_pic_zoom img.zoom').length>0) $('#cube_pic_zoom img.zoom').remove();
			$('#cube_pic_zoom').addClass('loader');
			$(this).children('img').remove();
			prod_img=0;
		});
		return false;
	});

	$('#cube_pictl_left li a').live('click',function(){
		var my_imgu = $(this).attr('href').split('#');
		var my_img = my_imgu[1];
		if ($('#cube_pic_zoom').is(':visible') && prod_img==0){
			prod_img = 1;
			my_img = my_img.replace('_lg.jpg','_zm.jpg')
			$('#cube_pic_zoom').addClass('loader');
			$('#cube_pic_zoom img.zoom').fadeOut(function(){
				$('#cube_pic_zoom img.zoom').remove();
				if ($('#cube_pic_xlg').length>0) $('#cube_pic_xlg').remove();

				var img_src = 'images/products/'+my_img;
				var img_id = (my_img.replace('_zm.jpg','_xlg.jpg'));

				var img_zm = new Image();
				$(img_zm).load(function () {
					var img1 = $(this);
					img1.hide();
					$('#cube_pic_zoom').append(img1);
					var img_xlg_src = 'images/products/'+(my_img.replace('_zm.jpg','_xlg.jpg'));
					var img_xlg = new Image();
					$(img_xlg).load(function () {
						var img2 = $(this);
						img2.hide();
						$('#cube_pic_zoom').removeClass('loader');
						$('#cube_pic_zoom').append('<div id="cube_pic_xlg"></div>');		
						$('#cube_pic_xlg').append(img2);

						img1.fadeIn(function(){
							img2.show();
							prod_img = 0;
						});
					}).error(function () {
						alert('Error: Image could not be loaded.');
						prod_img = 0;
			    	}).attr({
			        	src: img_xlg_src
					});						
				}).error(function () {
					alert('Error: Image could not be loaded.');
					prod_img = 0;
		    	}).attr({
		        	src: img_src,
		        	id: img_id,
		        	'class': 'zoom'
				});
			});
		}
		else{
			if (prod_img==0){
				prod_img = 1;
				$('#cube_pictl_right').addClass('loader');
				$('#cube_pictl_right img').fadeOut(function(){
					$(this).remove();
					var img_src = 'images/products/'+my_img;
	
					var img = new Image();
					$(img).load(function () {
						$(this).hide();
						$('#cube_pictl_right').removeClass('loader');
						$('#cube_pictl_right').append(this);
						$('#cube_pictlr_zoom').attr('href','#'+(my_img.replace('_lg.jpg','_zm.jpg')));
						$(this).fadeIn(function(){
							prod_img = 0;
						});
					}).error(function () {
						alert('Error: Image could not be loaded.');
						prod_img = 0;
			    	}).attr({
			        	src: img_src
					});
				});
			}
		}
		return false;
	});

	// SHOP MENU
	
	$('#shop_smenu_top li a').live('click',function(){
		var my_elem = $('#shop_menu_list li a.sel');
		var what = my_elem.attr('id').replace('shop_menu_','');
		var filter = $(this).attr('id').replace('filter_','');
		$('#shop_smenu').hide().remove();
		$('#shop_menu').append('<div id="shop_smenu" class="loader_grey"></div>');
		var pos_left = my_elem.offset().left-$('#shop_holder').offset().left;
		$('#shop_smenu').css({'left':pos_left+'px','min-width':my_elem.outerWidth()});
		$.post('scripts/get_shop_smenu.php',{gender:what,filter:filter},function(data){
			$('#shop_smenu').removeClass('loader_grey');
			$('#shop_smenu').html(data);
		});
		return false;
	});
	
	$('#shop_menu_list li a').live('click',function(){
		var my_elem = $(this);
		if ($(this).hasClass('sel')){
			$(this).removeClass('sel');
			$('#shop_smenu').hide().remove();		
		}
		else{
			if ($('#shop_smenu').length>0){
				$('#shop_smenu').hide().remove();
			}
			var what = $(this).attr('id').replace('shop_menu_','');
			$('#shop_menu_list li a').removeClass('sel');
			$(this).addClass('sel');
			
			if (what == 'brands'){
				$('#shop_menu').append('<div id="shop_smenu" class="loader_grey"></div>');
				var pos_left = my_elem.offset().left-$('#shop_holder').offset().left;
				$('#shop_smenu').css({'left':pos_left+'px','min-width':$(this).outerWidth()});
				$.post('scripts/get_shop_smenu.php',{brands:1},function(data){
					$('#shop_smenu').removeClass('loader_grey');
					$('#shop_smenu').html(data);
				});
			}
			else{
				$('#shop_menu').append('<div id="shop_smenu" class="loader_grey"></div>');
				var pos_left = my_elem.offset().left-$('#shop_holder').offset().left;
				$('#shop_smenu').css({'left':pos_left+'px','min-width':$(this).outerWidth()});
				$.post('scripts/get_shop_smenu.php',{gender:what},function(data){
					$('#shop_smenu').removeClass('loader_grey');
					$('#shop_smenu').html(data);
				});
			}
		}
		return false;
	});

	// HOME PROMO
	$('#promo_menu ul li a').live('click',function(){
		var what = $(this).attr('class').replace('pp_categ_','');
		var my_link = $(this);
		$('#promo_prod_holder').addClass('loader');
		$('#prod_box_wrap').fadeOut(function(){
			$('#prod_box_wrap').load('scripts/get_promo_prod.php',{pp_categ:what},function(){			
				$('#promo_menu ul li').removeClass('sel');
				my_link.parent().addClass('sel');		
				$('#promo_prod_holder').removeClass('loader');
				$('#prod_box_wrap').fadeIn(function(){

				});		
			});
		});	
		return false;
	});

	// HOME NEWS
	$('#news_menu ul li a').live('click',function(){
		var what = $(this).attr('href').replace('#','');
		var my_link = $(this);
		$('#articles_holder').addClass('loader');
		$('#articles_box_wrap').fadeOut(function(){
			$('#articles_box_wrap').load('scripts/get_'+what+'.php',function(){			
				$('#news_menu ul li').removeClass('sel');
				my_link.parent().addClass('sel');		
				$('#articles_holder').removeClass('loader');
				$('#articles_box_wrap').fadeIn(function(){

				});		
			});
		});	
		return false;
	});

	$('a.overlay_close').live('click',function(){
    	if ($('div.overlay').length>0){
    		$('div.overlay').hide().remove();
    		if ($('div.clipboard').length>0){
    			$('div.clipboard').remove();
    		}
    		is_overlay = 0;
    	}
    	return false;
    });

	// INFO

	$('#footer_info ul li a').live('click',function(){
		var my_id = $(this).attr('id').replace('info_','');
		$('#wrap').prepend('<div id="cube_info" class="overlay"></div>');
		$('#cube_info').load('include/cube_info.inc.php',function(){
			var wh = $(window).height();
			var ch = parseInt($('#cube_info_content').css('height').replace('px',''))+parseInt($('#cube_info_content').css('padding-top').replace('px',''));
			var st = $(window).scrollTop();
			var top_pos = Math.round((wh-ch)/2)+st;
			if (top_pos<0) top_pos = 10;
			$('#cube_info_content').css('top',top_pos+'px');
			$('#cube_info_icontent').addClass('loader');
			$('#cube_info').show();
			var ctop = 0;
			var btop = 0;
			var is = 0;
			if (my_id==1){ // order
				btop = 0;
				is = 1;
			}
			if (my_id==2){ // plata
				btop = -315;
				is = 1;
			}
			if (my_id==3){ // terms
				btop = -630;
				is = 1;
			}
			if (my_id==4){ // faq
				btop = -945;
				is = 1;
			}
			if (my_id==7){ // sugestii
				ctop = -400;
				btop = 0;
			}
			if (my_id==5){ // rank
				btop = -1260;
				is = 1;
			}
			if (my_id==6){ // ghid
				btop = -1575;
				is = 1;
			}
			$('#cube_iic_boxh').css('top',ctop+'px');	
			$('#cube_iic_content_boxh').css('top',btop+'px');
			$('#cube_info_icontent').removeClass('loader');
			$('#cube_iic_holder').fadeIn();
			if (is==1){
				$('#cube_iic_menu ul li a').removeClass('sel');
				$('#bc_'+my_id).addClass('sel');	
				$('#cube_iic_box'+my_id).jScrollPane({
					scrollbarWidth:20,
					dragMinHeight:120,
					dragMaxHeight:120
				});
			}
			
		});
		return false;
	});
	
	$('#cube_iic_menu ul li a').live('click',function(){
		var my_id = $(this).attr('id').replace('bc_','');
		$('#cube_iic_menu ul li a').removeClass('sel');
		$(this).addClass('sel');	
		$('#cube_iic_content_boxh').fadeOut(function(){
			$('#cube_iic_content').addClass('loader');
			var tpos = my_id*315-315;
			if (tpos>0) tpos = -tpos;
			$('#cube_iic_content_boxh').css('top',tpos+'px');
			$('#cube_iic_content').removeClass('loader');
			$('#cube_iic_content_boxh').fadeIn();
			$('#cube_iic_box'+my_id).jScrollPane({
				scrollbarWidth:20,
				dragMinHeight:120,
				dragMaxHeight:120
			});			
		});
		return false;
	});
	
	// WALLPAPER
	
	$('#misc_w_holder ul li a').live('click',function(){
		var my_id = $(this).attr('id').replace('wall_','');
		$('#wrap').prepend('<div id="cube_wallpaper" class="overlay"></div>');
		$('#cube_wallpaper').load('include/cube_wallpaper.inc.php',function(){
			var wh = $(window).height();
			var ch = parseInt($('#cube_wallpaper_content').css('height').replace('px',''))+parseInt($('#cube_wallpaper_content').css('padding-top').replace('px',''));
			var st = $(window).scrollTop();
			var top_pos = Math.round((wh-ch)/2)+st;
			if (top_pos<0) top_pos = 10;
			$('#cube_wallpaper_content').css('top',top_pos+'px');
			$('#cube_wallpaper').show();
			$('#cube_wallpaper_icontent').addClass('loader');
			$('#cube_wic_holder').load('scripts/get_wallpaper_content.php',{id:my_id},function(){
				$('#cube_wallpaper_icontent').removeClass('loader');
				$('#cube_wic_holder').fadeIn();
			});
		});
		return false;
	});
	
	$('#cube_wallpaper_nav a').live('click',function(){
		var my_id = $(this).attr('class').replace('nav_','');
		$('#cube_wic_holder').fadeOut(function(){
			$('#cube_wallpaper_icontent').addClass('loader');
			$('#cube_wic_holder').load('scripts/get_wallpaper_content.php',{id:my_id},function(){
				$('#cube_wallpaper_icontent').removeClass('loader');
				$('#cube_wic_holder').fadeIn();
			});			
		});
		return false;
	});
	
	// EVENTS

	$('div.event_box a').live('click',function(){
		var my_id = $(this).attr('id').replace('event_','');
		$('#wrap').prepend('<div id="cube_event" class="overlay"></div>');
		$('#cube_event').load('include/cube_event.inc.php',function(){
			var wh = $(window).height();
			var ch = parseInt($('#cube_event_content').css('height').replace('px',''))+parseInt($('#cube_event_content').css('padding-top').replace('px',''));
			var st = $(window).scrollTop();
			var top_pos = Math.round((wh-ch)/2)+st;
			if (top_pos<0) top_pos = 10;
			$('#cube_event_content').css('top',top_pos+'px');
			$('#cube_event').show();
			$('#cube_event_icontent').addClass('loader');
			$('#cube_eic_holder').load('scripts/get_events_content.php',{id:my_id},function(){
				$('#cube_event_icontent').removeClass('loader');
				$('#cube_eic_holder').fadeIn();
				$('#cube_eicr_icontent').jScrollPane({
					scrollbarWidth:20,
					dragMinHeight:120,
					dragMaxHeight:120
				});			
			});
		});
		return false;
	});

	$('#cube_event_nav a').live('click',function(){
		var my_id = $(this).attr('class').replace('nav_','');
		$('#cube_eic_holder').fadeOut(function(){
			$('#cube_event_icontent').addClass('loader');
			$('#cube_eic_holder').load('scripts/get_events_content.php',{id:my_id},function(){
				$('#cube_event_icontent').removeClass('loader');
				$('#cube_eic_holder').fadeIn();
				$('#cube_eicr_icontent').jScrollPane({
					scrollbarWidth:20,
					dragMinHeight:120,
					dragMaxHeight:120
				});			
			});			
		});
		return false;
	});

	// ARTICLES
	
	$('div.article_box a').live('click',function(){
		var my_id = $(this).attr('id').replace('news_','');
		$('#wrap').prepend('<div id="cube_article" class="overlay"></div>');
		$('#cube_article').load('include/cube_article.inc.php',function(){
			var wh = $(window).height();
			var ch = parseInt($('#cube_article_content').css('height').replace('px',''))+parseInt($('#cube_article_content').css('padding-top').replace('px',''));
			var st = $(window).scrollTop();
			var top_pos = Math.round((wh-ch)/2)+st;
			if (top_pos<0) top_pos = 10;
			$('#cube_article_content').css('top',top_pos+'px');
			$('#cube_article').show();
			$('#cube_article_icontent').addClass('loader');
			$('#cube_aic_holder').load('scripts/get_news_content.php',{id:my_id},function(){
				$('#cube_article_icontent').removeClass('loader');
				$('#cube_aic_holder').fadeIn();
				$('#cube_aicr_icontent').jScrollPane({
					scrollbarWidth:20,
					dragMinHeight:120,
					dragMaxHeight:120
				});			
			});
		});
		return false;
	});

	$('#cube_article_nav a').live('click',function(){
		var my_id = $(this).attr('class').replace('nav_','');
		$('#cube_aic_holder').fadeOut(function(){
			$('#cube_article_icontent').addClass('loader');
			$('#cube_aic_holder').load('scripts/get_news_content.php',{id:my_id},function(){
				$('#cube_article_icontent').removeClass('loader');
				$('#cube_aic_holder').fadeIn();
				$('#cube_aicr_icontent').jScrollPane({
					scrollbarWidth:20,
					dragMinHeight:120,
					dragMaxHeight:120
				});			
			});			
		});
		return false;
	});

	$('div.prod_info a').live('click',function(){
		var my_id = $(this).attr('id').replace('prod_','');
		$('#wrap').prepend('<div id="cube_product" class="overlay"></div>');
		$('#cube_product').load('include/cube_product.inc.php',{prod:my_id},function(){
			var wh = $(window).height();
			var ch = parseInt($('#cube_product_content').css('height').replace('px',''))+parseInt($('#cube_product_content').css('padding-top').replace('px',''));
			var st = $(window).scrollTop();
			var top_pos = Math.round((wh-ch)/2)+st;
			if (top_pos<0) top_pos = 10;
			$('#cube_product_content').css('top',top_pos+'px');
			$('#cube_product').show();
			is_overlay = 1;
		});
		return false;
	});
	
	
	$('#hhtm_login').live('click',function(){
		$('#wrap').prepend('<div id="cube_login" class="overlay"></div>');
		$('#cube_login').load('include/cube_login.inc.php',function(){
			var wh = $(window).height();
			var ch = parseInt($('#cube_login_content').css('height').replace('px',''))+parseInt($('#cube_login_content').css('padding-top').replace('px',''));
			var st = $(window).scrollTop();
			var top_pos = Math.round((wh-ch)/2)+st;
			if (top_pos<0) top_pos = 10;
			$('#cube_login_content').css('top',top_pos+'px');
			$('#cube_login').show();
		});
		return false;
	});

	$('#hhtm_register').live('click',function(){
		$('#wrap').prepend('<div id="cube_register" class="overlay"></div>');
		$('#cube_register').load('include/cube_register.inc.php',function(){
			var wh = $(window).height();
			var ch = parseInt($('#cube_register_content').css('height').replace('px',''))+parseInt($('#cube_register_content').css('padding-top').replace('px',''));
			var st = $(window).scrollTop();
			var top_pos = Math.round((wh-ch)/2)+st;
			if (top_pos<0) top_pos = 10;
			$('#cube_register_content').css('top',top_pos+'px');
			$('#cube_register').show();
		});
		return false;
	});

	$('#hhtm_account').live('click',function(){
		$('#wrap').prepend('<div id="cube_account" class="overlay"></div>');
		$('#cube_account').load('include/cube_account.inc.php',function(){
			var wh = $(window).height();
			var ch = parseInt($('#cube_account_content').css('min-height').replace('px',''))+parseInt($('#cube_account_content').css('padding-top').replace('px',''));
			var st = $(window).scrollTop();
			var top_pos = Math.round((wh-ch)/2)+st;
			if (top_pos<0) top_pos = 10;
			$('#cube_account_content').css('top',top_pos+'px');
			$('#cube_account').show();
		});
		return false;
	});

	$('#ppn_slide').css({'width':($('#ppn_slideo').width()-28)});
	$('#ppn_slide').slider({ 
		animate: 'true',
		value: 0,
		change: SliderChange,
	    slide: SliderSlide
	});

	$('#an_slide').css({'width':($('#an_slideo').width()-28)});
	$('#an_slide').slider({ 
		animate: 'true',
		value: 0,
		change: SliderChangeArticles,
	    slide: SliderSlideArticles
	});

	$('#ppn_content a').live('click',function(){
		var page = $(this).attr("id").replace('pp','');
		var my_link = $(this);
		var step = 401;
		var action_step = 0;
		if (is_action==0){
			is_action = 1;
			action_step = step*(page-1);
			$('#pp_box_holder').animate({left:'-'+action_step},300,function(){
				$('#ppn_content ul li a').filter(".sel").removeClass("sel");
				my_link.addClass("sel");
				pp_item = page;
				is_action = 0;
			});
			
		}
		return false;
	});
	
	$('#misc_b_navl').live('click',function(){
		var pos_left = $('#misc_b_bholder').css('left').replace('px','');
		var box_count = $('#misc_b_bholder').children('div.misc_b_box').size();
		var is_left = pos_left/290;
		if (is_left!=0 && is_misc_b==0){
			is_misc_b = 1;
			$('#misc_b_bholder').animate({left:'+=290px'},300,function(){
				is_misc_b = 0;
			});
		}
		return false;
	});

	$('#misc_b_navr').live('click',function(){
		var pos_left = $('#misc_b_bholder').css('left').replace('px','');
		var box_count = $('#misc_b_bholder').children('div.misc_b_box').size();
		var is_right = box_count + pos_left/290 - 1;
		if (is_right!=0 && is_misc_b==0){
			is_misc_b = 1;
			$('#misc_b_bholder').animate({left:'-=290px'},300,function(){
				is_misc_b = 0;
			});
		}
		return false;
	});
	
	$('#misc_w_navl').live('click',function(){
		var cleft = $('#misc_w_holder ul').css('left').replace('px','');
		if (cleft!=0 && is_misc_w==0){
			is_misc_w=1;
			$('#misc_w_holder ul').animate({left:'+=150px'},300,function(){
				is_misc_w=0;
			});
		}
		return false;
	});

	$('#misc_w_navr').live('click',function(){
		var hw = $('#misc_w_holder').width();
		var cw = $('#misc_w_holder ul').width();
		var cleft = $('#misc_w_holder ul').css('left').replace('px','');
		if ((parseInt(cw)+parseInt(cleft))>hw && is_misc_w==0){
			is_misc_w=1;
			$('#misc_w_holder ul').animate({left:'-=150px'},300,function(){
				is_misc_w=0;
			});
		}
		return false;
	});

	$('#ppn_slidel').live('click',function(){
		var hw = $('#prod_box_wrap').width();
		var cw = $('#prod_box_holder').width();
		var cleft = $('#prod_box_holder').position().left;
		var step = 192;
		if (cleft!=0 && act_slider==0){
			act_slider=1;

			var extra = (((hw+15)/step)%Math.floor((hw+15)/step)) * step;
			var maxScroll = parseInt(hw)-parseInt(cw)-extra;
			var spos = Math.round((100*(cleft+step))/maxScroll);

			$("#prod_box_holder").animate({'left':'+='+step+'px'},{queue:true});
			$("#ppn_slide .ui-slider-handle").animate({"left":spos+"%"},function(){
				act_slider = 0;				
			});
		}
		return false;
	});

	$('#ppn_slider').live('click',function(){
		var hw = $('#prod_box_wrap').width();
		var cw = $('#prod_box_holder').width();
		var cleft = $('#prod_box_holder').position().left;
		var step = 192;
		var is_right = parseInt(hw)-parseInt(cw)-parseInt(cleft) + 15;
		
		if (is_right<0  && act_slider==0){
			act_slider = 1;

			var extra = (((hw+15)/step)%Math.floor((hw+15)/step)) * step;
			var maxScroll = parseInt(hw)-parseInt(cw)-extra;
			var spos = Math.round((100*(cleft-step-15))/maxScroll);

			$("#prod_box_holder").animate({"left":"-="+step+"px"},{queue:true});
			$("#ppn_slide .ui-slider-handle").animate({"left":spos+"%"},function(){
				act_slider = 0;				
			});
		}
		return false;
	});

	$('#an_slidel').live('click',function(){
		var hw = $('#articles_box_wrap').width();
		var cw = $('#articles_box_holder').width();
		var cleft = $('#articles_box_holder').position().left;
		var step = 300;
		if (cleft!=0 && act_slider==0){
			act_slider=1;

			var extra = (((hw+15)/step)%Math.floor((hw+15)/step)) * step;
			var maxScroll = parseInt(hw)-parseInt(cw)-extra;
			var spos = Math.round((100*(cleft+step))/maxScroll);

			$("#articles_box_holder").animate({'left':'+='+step+'px'},{queue:true});
			$("#an_slide .ui-slider-handle").animate({"left":spos+"%"},function(){
				act_slider = 0;				
			});
		}
		return false;
	});

	$('#an_slider').live('click',function(){
		var hw = $('#articles_box_wrap').width();
		var cw = $('#articles_box_holder').width();
		var cleft = $('#articles_box_holder').position().left;
		var step = 300;
		var is_right = parseInt(hw)-parseInt(cw)-parseInt(cleft) + 15;
		
		if (is_right<0  && act_slider==0){
			act_slider = 1;

			var extra = (((hw+15)/step)%Math.floor((hw+15)/step)) * step;
			var maxScroll = parseInt(hw)-parseInt(cw)-extra;
			var spos = Math.round((100*(cleft-step-15))/maxScroll);

			$("#articles_box_holder").animate({"left":"-="+step+"px"},{queue:true});
			$("#an_slide .ui-slider-handle").animate({"left":spos+"%"},function(){
				act_slider = 0;				
			});
		}
		return false;
	});
	
	$(window).scroll(function(){
    	if  ($(window).scrollTop() > ($(document).height() - $(window).height() - $('#footer').height())){
    		var lpage = $('input#cs_page').val();
    		var lpages = $('input#cs_pages').val();
    		var npage = parseInt(lpage)+1;
    		if (prod_loading==0 && npage<=lpages){
				$('#shop_content').append('<div id="shop_load" class="loader">loading</div>');
				load_products(1,npage);
			}
        }
	});	
	
	$('#sel_size').live('click',function(){
		if ($(this).parent().children('ul').is(':visible')){
			$('#cube_pictri_size ul').hide();
		}
		else{
			$('#cube_pictri_size ul').show();		
		}
		return false;
	});
	
	$('#cube_pictri_size ul li a').live('click',function(){
		var size_id = $(this).parent().attr('id').replace('size_','');
		var size_value = $(this).attr('href').replace('#','');
		var size_svalue = $(this).html();
		$('input#cart_size').val(size_value);
		$('input#cart_size_id').val(size_id)
		$('#sel_size strong').html(size_svalue);
		$('#cube_pictri_size ul').hide();
		return false;
	});
	
	$('#hht_cart').hover(function(){
		$('#hht_cartc').show();
	},function(){
		$('#hht_cartc').hide();
	
	});

	$('#permalink_copy').live('mouseover',function(){
		var clip = new ZeroClipboard.Client();
		clip.addEventListener('mousedown',function() {
			clip.setText($('#permalink').val());
			$('#permalink').select();
		});
		clip.addEventListener('complete',function(client,text) {

		});
		clip.glue('permalink_copy');
	});

	$('#permalink_copy').live('click',function(){
			$('#permalink').select();
		return false;
	});	

	$('#cube_pictri_rating_selh a').live('mouseover',function(){
		var rating = $(this).attr('id').replace('rating_','');
		var rm = '';
		switch(rating){
			case '1':{
				rm = 'Sec';
				break;
			}
			case '2':{
				rm = 'Mediocru';
				break;
			}
			case '3':{
				rm = 'OK';
				break;
			}
			case '4':{
				rm = 'Foarte OK';
				break;
			}
			case '5':{
				rm = 'Superb';
				break;
			}
		}
		$(this).nextAll().addClass('rh');
		$(this).prevAll().addClass('rv');
		$('#cube_pictri_rating em').children('span').hide();
		$('#cube_pictri_rating em').prepend('<span id="rm">'+rm+'</span>');
	});

	$('#cube_pictri_rating_selh a').live('mouseout',function(){
		$('#cube_pictri_rating_selh a').removeClass('rv');
		$('#cube_pictri_rating_selh a').removeClass('rh');
		$('#rm').hide().remove();
		$('#cube_pictri_rating em').children('span').show();
	});
	
	$('#cube_pictri_rating_sel a').live('click',function(){
		var auth = $(this).parent().attr('class').replace('auth_','');
		if (auth==0){
			$('#cube_product_content a.overlay_close').trigger('click');
			$('#hhtm_login').trigger('click');
		}
		else{
			var prod_id = $('input#prod_id').val();
			var rank = $(this).attr('id').replace('rating_','');
			$('#cube_pictri_rating').addClass('loader_crem');
			$('#cube_pictri_ratingh').fadeOut(function(){
				$.post('scripts/scr_rank.php',{id:prod_id,rank:rank},function(){
					$('#cube_pictri_ratingh').load('scripts/get_rank.php',{id:prod_id},function(data){
						$('#cube_pictri_rating').removeClass('loader_crem');
						$('#cube_pictri_ratingh').fadeIn();				
					});
				});			
			});
		}
		return false;
	});
	
	if ($('#pp_box_holder').length>0){
		var items = $('#pp_box_holder .pp_box').size();
		pp_items = items;
		if (items>1){
			start_autoplay();
			$('#promo_promo').live('mouseover',function(){
				stop_autoplay();
			});
	
			$('#promo_promo').live('mouseout',function(){
				start_autoplay();
			});
		}		
	}
	
	$('#btn_buy').live('click',function(){
		if (is_buy==0){
			is_buy = 1;
			var prod_id = $('input#prod_id').val();
			var cart_qty = $('input#cart_qty').val();
			var cart_size = $('input#cart_size').val();
			var cart_size_id = $('input#cart_size_id').val();
			var cart_price = $('input#cart_price').val();
			if (cart_size_id==''){
				$('#cube_pictri_msg strong').show();
				is_buy = 0
			}
			else{
				$('#cube_pictri_msg strong').hide();
				$.post('scripts/scr_cart_add.php',{prod_id:prod_id,cart_qty:cart_qty,cart_size_id:cart_size_id},function(data){
					$('#hht_carth').load('scripts/get_cart.php');
					$('#cube_pictri_buy a').fadeOut(function(){
						is_buy=0;
						$('#cube_pictri_buy').prepend('<p>Produsul a fost adaugat</p>');
						$('#cube_pictri_buy p').fadeIn(function(){
							$('input#cart_size').val('');
							$('input#cart_size_id').val('')
							$('#sel_size strong').html('Selecteaza marimea');
							var t = setTimeout("$('#cube_pictri_buy p').fadeOut(function(){$(this).remove(); $('#cube_pictri_buy a').fadeIn();});",2000)
						});
					
					});
				});
			}
		}
		return false;
	})
	
	$('div.carti_boxc .cbox_c5 a').live('click',function(){
		var pos = $(this).attr("id").replace('dc_','');
		$.post('scripts/scr_cart_delete.php',{pos:pos},function(){
			window.location.reload();
		});
		return false;
	});
	
	$('#hht_cartc_bottom a.cartcb_empty').live('click',function(){
		$.post('scripts/scr_cart_empty.php',function(){
			window.location.reload();
		})
		return false;
	});

	$('#hht_cartc_bottom a.cartcb_order').live('click',function(){
		$('#wrap').prepend('<div id="cube_checkout" class="overlay"></div>');
		$('#cube_checkout').load('include/cube_checkout.inc.php',function(){
			var wh = $(window).height();
			var ch = parseInt($('#cube_checkout_content').css('height').replace('px',''))+parseInt($('#cube_checkout_content').css('padding-top').replace('px',''));
			var st = $(window).scrollTop();
			var top_pos = Math.round((wh-ch)/2)+st;
			if (top_pos<0) top_pos = 10;
			$('#cube_checkout_content').css('top',top_pos+'px');
			$('#cube_checkout').show();
			$('#cube_chks1c_contenth').jScrollPane({
				scrollbarWidth:20,
				dragMinHeight:120,
				dragMaxHeight:120
			});
		});
		return false;
	});
	
	$('div.cube_chk_cbox .ccol7 a').live('click',function(){
		var pos = $(this).attr("id").replace('dcc_','');
		$.post('scripts/scr_cart_delete.php',{pos:pos},function(data){
			var cvalue = data;
			if (cvalue<100 && $('#cube_chks1_nav a').is(':visible')){
				$('#cube_chks1_nav a').hide();
				$('#cube_chks1c_bar .bcl1').html('Comanda minima este de 100 RON');
			}
			if (cvalue>=100 && !$('#cube_chks1_nav a').is(':visible')){
				$('#cube_chks1_nav a').show();
				$('#cube_chks1c_bar .bcl1').html('&nbsp;');
			}			
			$('#cube_chks1c_contenth').load('scripts/get_cart_checkout.php',function(){
				$('#cube_chks1c_bar div.bcr').html(cvalue+',-')
				$('#cube_chks1c_contenth').jScrollPane({
					scrollbarWidth:20,
					dragMinHeight:120,
					dragMaxHeight:120
				});			
			});
		});
		return false;
	});

	$('div.cube_chk_cbox .ccol5 a').live('click',function(){
		if ($(this).hasClass('cminus')){
			var type = 0;
			var pos = $(this).attr("id").replace('cqm_','');		
		}
		else{
			var type = 1;
			var pos = $(this).attr("id").replace('cqp_','');				
		}
		$.post('scripts/scr_cart_qty.php',{pos:pos,type:type},function(data){
			var cvalue = data;
			if (cvalue<100 && $('#cube_chks1_nav a').is(':visible')){
				$('#cube_chks1_nav a').hide();
				$('#cube_chks1c_bar .bcl1').html('Comanda minima este de 100 RON');
			}
			if (cvalue>=100 && !$('#cube_chks1_nav a').is(':visible')){
				$('#cube_chks1_nav a').show();
				$('#cube_chks1c_bar .bcl1').html('&nbsp;');
			}			
			$('#cube_chks1c_contenth').load('scripts/get_cart_checkout.php',function(){
				$('#cube_chks1c_bar div.bcr').html(cvalue+',-')
				$('#cube_chks1c_contenth').jScrollPane({
					scrollbarWidth:20,
					dragMinHeight:120,
					dragMaxHeight:120
				});			
			});
		});
		return false;
	});

	$('#cube_checkout_1_back').live('click',function(){
		show_checkout(1);
		return false;
	});
	$('#cube_checkout_2_back').live('click',function(){
		show_checkout(2);
		return false;
	});
	$('#cube_checkout_3_back').live('click',function(){
		show_checkout(3);
		return false;
	});
	$('#cube_checkout_4_back').live('click',function(){
		show_checkout(4);
		return false;
	});

	$('#cube_checkout_5_back').live('click',function(){
		show_checkout(5);
		return false;
	});

	$('#cube_checkout_1').live('click',function(){
		show_checkout(1);
		return false;
	});

	$('#cube_checkout_2').live('click',function(){
		show_checkout(2);
		return false;
	});

	$('#cube_checkout_3').live('click',function(){
	   	var auth = $('#cube_chk_step1').attr('class').replace('auth_','');
		if (auth==0){	
			var error = 0;
			var validate = 0;
			$('#form_checkout_register1 p.err').html('');
			if ($('input#user_terms').parent('div').hasClass('err')) $('input#user_terms').parent('div').removeClass('err');
			if ($('input#user_account').parent('div').hasClass('err')) $('input#user_account').parent('div').removeClass('err');
			if ($('input#user_email').parent('div').hasClass('err')) $('input#user_email').parent('div').removeClass('err');
			if ($('input#user_password').parent('div').hasClass('err')) $('input#user_password').parent('div').removeClass('err');
			if ($('input#user_password1').parent('div').hasClass('err')) $('input#user_password1').parent('div').removeClass('err');
			if ($('input#user_code').parent('div').hasClass('errl')) $('input#user_code').parent('div').removeClass('errl');
			if (trim($('input#user_account').val())==''){
				$('input#user_account').parent('div').addClass('err');
				error = 1;
			}
			if (!isValidEmailAddress(trim($('input#user_email').val()))){
				$('input#user_email').parent('div').addClass('err');
				error = 1;
			}
			if (trim($('input#user_password').val())==''){
				$('input#user_password').parent('div').addClass('err');
				error = 1;
			}
			if (trim($('input#user_password1').val())==''){
				$('input#user_password1').parent('div').addClass('err');
				error = 1;
			}
			if (trim($('input#user_code').val())==''){
				$('input#user_code').parent('div').addClass('errl');
				error = 1;
			}
			if (!$('input#user_terms').is(':checked')){
				$('input#user_terms').parent('div').addClass('err');
				error = 1;
			}
			if (error==1){
				$('#form_checkout_register1 p.err').html('*Toate campurile trebuie completate pentru a trece la pasul urmator.');
			}
			else{
				var validate = trim($('input#user_account').val());
				$.post('scripts/get_validation.php',{type:0,validate:encodeURIComponent(validate)},function(data){
					if (data==1){
						validate = trim($('input#user_email').val());
						$.post('scripts/get_validation.php',{type:1,validate:encodeURIComponent(validate)},function(data){
							if (data==1){
								validate = trim($('input#user_code').val());
								$.post('scripts/get_validation.php',{type:2,validate:encodeURIComponent(validate)},function(data){
									if (data==1){
										show_checkout(3);
									}
									else{
										$('#form_checkout_register1 p.err').html('*Codul introdus este gresit!');
										$('input#user_code').parent('div').addClass('errl');
										$('input#user_code').val('');
										$('#code img').attr('src','scripts/get_code.php?k='+Math.random());
										$('input#user_terms').attr('checked',0);
									}
								});						
							}
							else{
								$('#form_checkout_register1 p.err').html('*Adresa de e-mail este deja inregistrata!');
								$('input#user_email').parent('div').addClass('err');
								$('input#user_terms').attr('checked',0);
							}
						});
					
					}
					else{
						$('#form_checkout_register1 p.err').html('*Username-ul ales exista deja!');
						$('input#user_account').parent('div').addClass('err');
						$('input#user_terms').attr('checked',0);
					}
				});
			}
		}
		else{
			show_checkout(3);
		}
		return false;
	});

	$('#cube_checkout_4').live('click',function(){
		var error = 0;
	   	var auth = $('#cube_chk_step1').attr('class').replace('auth_','');
	   	
		$('div.chks3_err').html('&nbsp;');
		if ($('input#user_fname').parent('div').hasClass('err')) $('input#user_fname').parent('div').removeClass('err');
		if ($('input#user_lname').parent('div').hasClass('err')) $('input#user_lname').parent('div').removeClass('err');
		if (auth==0){
			if ($('select#user_gender').parent('div').hasClass('err')) $('select#user_gender').parent('div').removeClass('err');
			if ($('select#user_bday').parent('div').hasClass('err')) $('select#user_bday').parent('div').removeClass('err');
			if ($('select#user_bmonth').parent('div').hasClass('err')) $('select#user_bmonth').parent('div').removeClass('err');
			if ($('select#user_byear').parent('div').hasClass('err')) $('select#user_byear').parent('div').removeClass('err');
			if ($('textarea#user_address').parent('div').hasClass('err')) $('textarea#user_address').parent('div').removeClass('err');
			if ($('input#user_city').parent('div').hasClass('err')) $('input#user_city').parent('div').removeClass('err');
			if ($('input#user_state').parent('div').hasClass('err')) $('input#user_state').parent('div').removeClass('err');
			if ($('input#user_zip').parent('div').hasClass('err')) $('input#user_zip').parent('div').removeClass('err');
		}
		if ($('textarea#cinfo_address').parent('div').hasClass('err')) $('textarea#cinfo_address').parent('div').removeClass('err');
		if ($('input#cinfo_city').parent('div').hasClass('err')) $('input#cinfo_city').parent('div').removeClass('err');
		if ($('input#cinfo_state').parent('div').hasClass('err')) $('input#cinfo_state').parent('div').removeClass('err');
		if ($('input#cinfo_zip').parent('div').hasClass('err')) $('input#cinfo_zip').parent('div').removeClass('err');
		if ($('input#user_phone').parent('div').hasClass('err')) $('input#user_phone').parent('div').removeClass('err');
		if ($('input#address_type0').parent('div').hasClass('err')) $('input#address_type0').parent('div').removeClass('err');
		if (trim($('input#user_fname').val())==''){
			$('input#user_fname').parent('div').addClass('err');
			error = 1;
		}
		if (trim($('input#user_lname').val())==''){
			$('input#user_lname').parent('div').addClass('err');
			error = 1;
		}
		if (auth==0){
			if (trim($('select#user_gender').val())==''){
				$('select#user_gender').parent('div').addClass('err');
				error = 1;
			}
			if (trim($('select#user_bday').val())==''){
				$('select#user_bday').parent('div').addClass('err');
				error = 1;
			}
			if (trim($('select#user_bmonth').val())==''){
				$('select#user_bmonth').parent('div').addClass('err');
				error = 1;
			}
			if (trim($('select#user_byear').val())==''){
				$('select#user_byear').parent('div').addClass('err');
				error = 1;
			}
			if (trim($('textarea#user_address').val())==''){
				$('textarea#user_address').parent('div').addClass('err');
				error = 1;
			}
			if (trim($('input#user_city').val())==''){
				$('input#user_city').parent('div').addClass('err');
				error = 1;
			}
			if (trim($('input#user_state').val())==''){
				$('input#user_state').parent('div').addClass('err');
				error = 1;
			}
			if (trim($('input#user_zip').val())==''){
				$('input#user_zip').parent('div').addClass('err');
				error = 1;
			}
		}
		if (!isValidPhone(trim($('input#user_phone').val())) || trim($('input#user_phone').val())==''){
			$('input#user_phone').parent('div').addClass('err');
			error = 1;
		}
	   	if(!$('#address_type0').is(':checked') && !$('#address_type1').is(':checked')){
	   		$('input#address_type0').parent('div').addClass('err');
			error = 1;
	   	}
	   	if ($('#address_type1').is(':checked')){
			if (trim($('textarea#cinfo_address').val())==''){
				$('textarea#cinfo_address').parent('div').addClass('err');
				error = 1;
			}
			if (trim($('input#cinfo_city').val())==''){
				$('input#cinfo_city').parent('div').addClass('err');
				error = 1;
			}
			if (trim($('input#cinfo_state').val())==''){
				$('input#cinfo_state').parent('div').addClass('err');
				error = 1;
			}
			if (trim($('input#cinfo_zip').val())==''){
				$('input#cinfo_zip').parent('div').addClass('err');
				error = 1;
			}
	   	}
	   	if (error==1){
			$('div.chks3_err').html('<p>*Toate campurile trebuie completate pentru a trece la pasul urmator.</p>');
		}
		else{
			if (auth==0){
				var loader_height = $('#cube_chks3_content').css('height').replace('px','');
				$('#cube_chk_contenth').fadeOut();
				$('#cube_chk_loader').css({'height':loader_height+'px'});
				$('#cube_chk_loader').fadeIn(function(){
					var address_type = 0;
					if ($('#address_type1').is(':checked')){
						address_type = 1;
					}
					var inputs = [];
					$(':input', $('#form_checkout_register1')).each(function() {
						inputs.push(this.name + '=' + encodeURIComponent(trim(this.value)));
					})
					$(':input', $('#form_checkout_register2')).each(function() {
						inputs.push(this.name + '=' + encodeURIComponent(trim(this.value)));
					})
					jQuery.ajax({
						data: inputs.join('&'),
						url: 'scripts/scr_register.php',
						timeout: 10000,
						type: 'post',
						error: function() {
							$('#cube_chk_loader').fadeOut();
							$('#cube_chk_contenth').fadeIn(function(){
								alert('Ne pare rau dar inregistrarea nu se poate face momentan.\nVa rugam incercati mai tarziu.');
							});
							
						},
						success: function(r) { 
							switch(r){
								case "1":
									show_checkout(4,1,address_type);
									break;
								case "2": // acc
									$('#form_checkout_register1 p.err').html('*Username-ul ales exista deja!');
									$('input#user_account').parent('div').addClass('err');
									$('input#validate_step_1').val('0');
									$('input#user_code').val('');
									$('#code img').attr('src','scripts/get_code.php?k='+Math.random());
									show_checkout(2);
									break;
								case "3": // email
									$('#form_checkout_register1 p.err').html('*Adresa de e-mail este deja inregistrata!');
									$('input#user_email').parent('div').addClass('err');
									$('input#user_terms').attr('checked',0);
									$('input#user_code').val('');
									$('#code img').attr('src','scripts/get_code.php?k='+Math.random());
									show_checkout(2);
									break;
								case "4": // both
									$('#form_checkout_register1 p.err').html('*Username-ul ales si adresa de e-mail este deja inregistrata!');
									$('input#user_account').parent('div').addClass('err');
									$('input#user_email').parent('div').addClass('err');
									$('input#user_terms').attr('checked',0);
									$('input#user_code').val('');
									$('#code img').attr('src','scripts/get_code.php?k='+Math.random());
									show_checkout(1);
									break;
								default:
									$('#cube_chk_loader').fadeOut();
									$('#cube_chk_contenth').fadeIn(function(){
										alert('Ne pare rau dar inregistrarea nu se poate face momentan.\nVa rugam incercati mai tarziu.');
									});
									break;
							}
						}
					});
				});
			}
			else{
				$('#cship_name').html($('input#user_fname').val()+' '+$('input#user_lname').val());
				$('#cship_phone').html($('input#user_phone').val());
				if ($('#address_type1').is(':checked')){
					$('#cship_address').html($('textarea#cinfo_address').val());	
					$('#cship_city').html($('input#cinfo_city').val());
					$('#cship_state').html($('input#cinfo_state').val());
					$('#cship_zip').html($('input#cinfo_zip').val());

					$('#ship_address').val($('textarea#cinfo_address').val());
					$('#ship_city').val($('input#cinfo_city').val());
					$('#ship_state').val($('input#cinfo_state').val());
					$('#ship_zip').val($('input#cinfo_zip').val());
				}
				else{
					$('#cship_address').html($('textarea#user_address').val());	
					$('#cship_city').html($('input#user_city').val());
					$('#cship_state').html($('input#user_state').val());
					$('#cship_zip').html($('input#user_zip').val());				

					$('#ship_address').val($('textarea#user_address').val());
					$('#ship_city').val($('input#user_city').val());
					$('#ship_state').val($('input#user_state').val());
					$('#ship_zip').val($('input#user_zip').val());
				}
				show_checkout(4);		
			}
		}
		return false;
	});

	$('#cube_checkout_5').live('click',function(){
		$('#cube_chks5_content').load('scripts/get_cart_checkoutc.php',function(){
			show_checkout(5);
		});
		return false;
	});
	$('#cube_checkout_6').live('click',function(){
		show_checkout(6);
		return false;
	});
	$('#cube_checkout_7').live('click',function(){
//		$('#cube_chks6_nav a').hide();
		var errorl = 0;
		var errorp = 0;
		var error = 0;
		var msg = '';
		$('#chks6_err').html('&nbsp;');
		if (!$('input[name="livrare"]').is(':checked')){
			errorl = 1;
		}
		if (!$('input[name="plata"]').is(':checked')){
			errorp = 1;
		}
		if (errorl==1 || errorp==1 ){
			error = 1;
			if (errorl==1 && errorp==1){
				msg = '*Selecteaza modalitatea de plata si de livrare';
			}
			else{
				if (errorl==1){
					msg = '*Selecteaza modalitatea de livrare';
				}
				if (errorp==1){
					msg = '*Selecteaza modalitatea de plata';
				}
			}
		}
		if (error == 1){
			$('#chks6_err').html(msg);
		}
		else{
			$('#order_delivery').val($("input[name='livrare']:checked").val());
			$('#order_payment').val($("input[name='plata']:checked").val());
			$('#bill_fname').val($('input#user_fname').val());
			$('#bill_lname').val($('input#user_lname').val());
			$('#bill_phone').val($('input#user_phone').val());
			$('#bill_email').val($('input#user_email').val());
			$('#bill_address').val($('textarea#user_address').val());
			$('#bill_city').val($('input#user_city').val());
			$('#bill_state').val($('input#user_state').val());
			$('#bill_zip').val($('input#user_zip').val());

			var inputs = [];
			$(':input', $('#form_checkout_register3')).each(function() {
				inputs.push(this.name + '=' + encodeURIComponent(trim(this.value)));
			})
			jQuery.ajax({
				data: inputs.join('&'),
				url: $('#form_checkout_register3').attr('action'),
				timeout: 10000,
				type: 'post',
				error: function() {
					alert('Ne pare rau cererea nu poate fi procesata.\nVa rugam incercati mai tarziu.');
					$('#cube_chks6_nav a').show();
				},
				success: function(r) {
					switch(r){
						case "1":
							$('#hht_carth').load('scripts/get_cart.php');
							show_checkout(7);
							break;
						case "2": // cart problems
							$('#cube_chks1c_bar .bcl1').html('Produsele marcate nu mai sunt disponibile');
							$('#cube_chks1c_contenth').load('scripts/get_cart_checkout.php',function(){
								show_checkout(1);
							});
							$('#cube_chks6_nav a').show();							
							break;
						default:
							alert('Ne pare rau cererea nu poate fi procesata.\nVa rugam incercati mai tarziu.');
							$('#cube_chks6_nav a').show();
							break;
					}
				}
			});		
		}
		return false;
	});
	
	$('#form_hsearch').submit(function(){
		if ($('#sq').val()=='' || $('#sq').val()=='cauta in shop'){
			return false;
		}
		else{
			return true;
		}
	});
	
	$('div.carti_box .cbox_c1 a, div.carti_box .cbox_c2 a').live('click',function(){
		var my_id = $(this).attr('class').replace('prod_','');
		$('#wrap').prepend('<div id="cube_product" class="overlay"></div>');
		$('#cube_product').load('include/cube_product.inc.php',{prod:my_id},function(){
			var wh = $(window).height();
			var ch = parseInt($('#cube_product_content').css('height').replace('px',''))+parseInt($('#cube_product_content').css('padding-top').replace('px',''));
			var st = $(window).scrollTop();
			var top_pos = Math.round((wh-ch)/2)+st;
			if (top_pos<0) top_pos = 10;
			$('#cube_product_content').css('top',top_pos+'px');
			$('#cube_product').show();
			is_overlay = 1;
		});
		return false;
	});

});
