
$(document).ready(function () { 
	$('a[rel]').lightBox(); 
	$('.easy_slideshow').each(function(){
		speed = parseInt($(this).attr('speed'));
		$(this).find('a').fadeOut(0);
		$(this).find('.index_0').fadeIn(1000);
		$(this).everyTime(parseInt($(this).attr('speed')), function(i){ index=i%$(this).find('a').length; $(this).find('a').fadeOut(1000); $(this).find('.index_'+index).fadeIn(1000); });
	}); 
});


function easy_slideshow(){
}

function addSuccess(){
	$("#cart_sum b").animate( { backgroundColor:"#FF6666" }, 500, 0, function(){ $("#cart_sum b").animate( { backgroundColor:"#FFFFFF" }, { queue:false, duration:2000 } ) } );
}

function addSuccess_order(){
	$("#order_cart_sum b").animate( { backgroundColor:"#FF6666" }, 500, 0, function(){ $("#order_cart_sum b").animate( { backgroundColor:"#FFFFFF" }, { queue:false, duration:2000 } ) } );
}

function add2cart(aurl, content, func){
$.ajax({
  url: aurl,
  cache: false,
  success: function(html){
    $("#"+content).html(html);
    func();
  }
});
}

function modifSelected(){
	ok = true;
	$('.item_modif select').each( function(){ if($(this).val()==''){ ok=false; } } );
	return ok;
}

function getAllModif(){
	str = "";
	$('.item_modif select').each( function(){ str+="::"+$(this).val(); } );
	return str;
}


stop_scroll = false;

function slider(container, content, direction){ 
	if(!stop_scroll){
		leftPos_int = parseInt($('#'+container).css('left'))-(direction)*parseInt($('#'+content).width());
		if(direction==-1){
			if(leftPos_int>0){ 
				stop_scroll=false;
				return;
			}
		}else{
			if(leftPos_int*(-1)>$('#'+container+' .product_thumb').length*136){ 
				stop_scroll=false;
				return;
			}
		}
		leftPos = leftPos_int+'px';
		if($('#'+container).width()<=((parseInt(leftPos))*(-1))){
			$('#'+container).animate( { left:'0px' }, 1000, '', function(){ stop_scroll=false; } );
		}else{
			$('#'+container).animate( { left:leftPos }, 1000, '', function(){ stop_scroll=false; } );
		}
	}
}

function submitSearchForm(url, form){
	location = url + document.forms['search'].elements['q'].value;
}

function getMouseXY(e) {
  if (document.all) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  return { x:tempX, y:tempY }
}

function ajax(a_url, a_obj, top_pos){
			$.ajax({
			  async: true,
			  url: a_url,
			  cache: false,
			  beforeSend: function(){
			  	//$("#"+a_obj).slideUp(1000, function(){  });
			  },
			  success: function(html){
			    $("#"+a_obj).html(html);
			    if(top_pos) $("#"+a_obj).animate({height:"150px", top:top_pos}, 1000);
			  },
			  //timeout: 20,
			  complete: function(html){
			    
			  }
			});
}

function post(a_url, a_obj, form){
			$.ajax({
			  type: "POST",
			  async: true,
			  url: a_url,
			  cache: false,
			  data: formData2QueryString(form),
			  beforeSend: function(){
			  	$("#"+a_obj).fadeOut(500, function(){  });
			  },
			  success: function(html){
			    $("#"+a_obj).html(html);
			    $("#"+a_obj).fadeIn(1000);
			  },
			  //timeout: 20,
			  complete: function(html){
			    
			  }
			});
}

function setSelected(obj, val){
	for(i=0; i<obj.options.length; i++){
		if(obj.options[i].value==parseInt(val)) index=i;
	}
	if(index) obj.options[index].selected=true;
}

function formData2QueryString(docForm) {

        var strSubmit       = '';
        var formElem;
        var strLastElemName = '';
        
        for (i = 0; i < docForm.elements.length; i++) {
                formElem = docForm.elements[i];
                switch (formElem.type) {
                        // Text, select, hidden, password, textarea elements
                        case 'text':
                        case 'hidden':
                        case 'password':
                        case 'textarea':
				formElem.value = formElem.value.replace(/&/g, '%26');
				formElem.value = formElem.value.replace(/\+/g, '%2B');
				strSubmit += formElem.name + '=' + formElem.value + '&';
                        break;
                        case 'select-one':
                        	strSubmit += formElem.name + '=' + escape(formElem.options[formElem.selectedIndex].value) + '&';
                        break;
                        case 'checkbox':
                        	if(formElem.checked == true) strSubmit += formElem.name + '=' + escape(formElem.value) + '&';
                        break;
                        case 'radio':
	                        if(formElem.checked == true) strSubmit += formElem.name + '=' + escape(formElem.value) + '&';
                }
        }
        return strSubmit;
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return { x:curleft, y:curtop };
}

function showPostForm(obj){
	document.getElementById('NL_overlay').style.display = 'block';
	document.getElementById(obj).style.display = 'block';
	try{
		document.getElementsByTagName("html")[0].style.overflow = "hidden";
	}catch(e){}
}

function closePostForm(obj){
	
	clearPostForm(obj);
	
	document.getElementById('NL_overlay').style.display = 'none';
	document.getElementById(obj).style.display = 'none';
	try{
		document.getElementsByTagName("html")[0].style.overflow = "";
	}catch(e){}
}

function clearPostForm(obj){
	document.getElementById(obj + '_form').reset();
}

function format_float(number){
	var str = new String();
	str = number + "";
	arr = str.split(/\./);
	if(arr.length>1){
		if((arr[1]).length<2)
			str = str + "0";
		if((arr[1]).length>2)
			str = Math.round(str*100)/100;
	}else{
		str = str + ".00";
	}
	return str;
}

function checkInt(x){
	var filter  = /^[0-9]*$/;
	if (filter.test(x)) return true;
	else return false;
}

function valid_email(){
	if(checkMail(document.forms['news'].elements['email'].value)) 
		document.forms['news'].submit();
	else
		alert('Neteisingai įvestas el. paštas.');
}

function checkMail(x)
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) return true;
	else return false;
}

function valid_number(x)
{
	var filter  = /^([0-9])*$/;
	if (filter.test(x)) return true;
	else return false;
}

function inputFocus(field){
	if(document.getElementById(field.name + '_').value != 1) 
		field.value='';
}

function inputBlur(field, text){
	if(document.getElementById(field.name + '_').value != 1 && field.value != '') 
		document.getElementById(field.name + '_').value = 1;
	if(document.getElementById(field.name + '_').value != 1) 
		field.value = text;
}

function show_hide(id){
	var obj = document.getElementById(id);
	if(obj.style.display=='none'){
		//obj.style.visibility='visible';
		//obj.style.position='static';
		obj.style.display = 'block';
	}else{
		//obj.style.visibility='hidden';
		//obj.style.position='absolute';
		obj.style.display = 'none';
	}
	
}

