function openVerMenu(mid){
	$('ul.submenu:visible').each(function() {
		var id = $(this).attr('id').split('_');
		
		if(id[1] == 207 || id[1] == 33){
			$("#vsubmenu_207").show();
		}else{
			$("#vsubmenu_"+id[1]).hide(200);
		}
		$("#vmenu_group_"+mid[1]).css("background","none");
		saveOpenedMenu(id[1],0);
	})
	if($("#vsubmenu_"+mid).css("display")=="none"){
		if(mid == 207 || mid == 33){
			$("#vsubmenu_207").show();
		}
		$("#vsubmenu_"+mid).show(200);
		$("#vmenu_group_"+mid).css("background","#f1f4f0");
		saveOpenedMenu(mid,1);
	}else{
		if(mid == 207 || mid == 33){
			$("#vsubmenu_207").show();
		}
		$("#vsubmenu_"+mid).hide(200);
		$("#vmenu_group_"+mid).css("background","none");
		saveOpenedMenu(mid,0);
	}
}
function saveOpenedMenu(mid,stat){
	$.ajax({
	   type: "get",
	   url: saveMenuScript,
	   data: "mid="+mid+"&stat="+stat,
	   success: function(msg){
		 void(0);
	   }
	 });
}

var count_items;
var count_items1;
$(document).ready(function() {
Cufon.replace('.level_1,#promo_left .promo_text a,#promo_right .promo_text a,.post .front_news_title,#top_logo_text,.page_title,#promo_center_title h1,#promo_center_title #title2'); // Works without a selector engine
	$('input[type=text][title!=""]').each(function() {
	if ($.trim($(this).val()) == '') $(this).val($(this).attr('title'));
	if ($(this).val() == $(this).attr('title')) $(this).addClass('exampleText');
	}).focus(switchText).blur(switchText);
	$("a.zoom").fancybox({
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
	});
	/*$("#contactform").validate({
	
		rules: {
			name: {
				required: true,
				minlength: 2
				},
			email: {
				required: true,
				email: true
			},
			phone: {
				required: true,
			},
			comment: {
				required: true,
				minlength: 2
			},
		},
		
		messages: {
			name: validName,
			email: validEmail,
			phone: validRequired,
			comment: validRequired,
			}
		});*/
  $('a._blank').click( function() {
      window.open(this.href);
      return false;
	 
  });
  
  $("#vsubmenu_207").show();
  $("#vsubmenu_33").show();
  //$('.level_1 a,.level_1 a:hover,.level_1,.level_1 .act,#left_menu ul li ul').corner('3px');
	

	if($(".noshow").get(0)){
			$("#basketItemsWrap").hide();
			$("#search_blox").css("height","96px");
			$("#search_blox_bottom_arrow").show();
		}else{
			$("#basketItemsWrap").show();
			$("#search_blox").css("height","141px");
			$("#search_blox_bottom_arrow").css("display","none");
		}
	
	count_items = $(".content > div > .cupons_item").length;
	count_items1 = $(".content > div > .products_item").length;
	//console.log(count_items);
	//console.log(count_items1);
	
	/*if($("#ifreims").get(0)){
		$("#promo_right").hide();
		$(".banners").hide();
	}*/
/*	if(!$(".cupons_item").get(0)){
		$("#empty_basket_msg").show();
		$("#print_bigbtn").remove();
	}else{
		$("#empty_basket_msg").hide();
		$("#print_bigbtn").show();
	}
	if(!$(".products_item").get(0)){
		$("#empty_basket_msg").show();
		$("#print_bigbtn1").remove();
	}else{
		$("#empty_basket_msg").hide();
		$("#print_bigbtn1").show();
	}*/	
});
	function DraugiemSay( title, url, titlePrefix ){
		 window.open(
		  'http://www.draugiem.lv/say/ext/add.php?title=' + encodeURIComponent( title ) +
		  '&link=' + encodeURIComponent( url ) +
		  ( titlePrefix ? '&titlePrefix=' + encodeURIComponent( titlePrefix ) : '' ),
		  '',
		  'location=1,status=1,scrollbars=0,resizable=0,width=530,height=400'
		 );
		 return false;
	}

jQuery.event.add(window, "load", resizeFrame);
jQuery.event.add(window, "resize", resizeFrame);

function resizeFrame() 
{
    var h = $(window).height();
    var w = $(window).width();
    $("#chakar").css('height',h);
}


function switchText(){
	if ($(this).val() == $(this).attr('title'))
		$(this).val('').removeClass('exampleText');
	else if ($.trim($(this).val()) == '')
		$(this).addClass('exampleText').val($(this).attr('title'));
}


function save_value(link,id,check,value2,value3,value,obj){
	if((value!=0) && (check=="on")){
		$.ajax({
			url : link,
			data : { save_value:id,value2:value2,value3:value3,value:value},
			type : 'post',
			success : function(msg){
				$('#prod_'+id+'_is').remove();
				/*var currentId = 'prod_'+value2+'_'+id;
				$('label[for=\"' + currentId + '\"]').remove();*/
				$('#prod_'+value2+'_is').remove();
				/*var currentId = 'prod_'+value2;
				$('label[for=\"' + currentId + '\"]').remove();*/
				var temp = $('#basketItemsWrap #basketcount').html();	
				temp++;
				$('#basketItemsWrap #basketcount').html(temp);
				if($("#basketItemsWrap").css("display")=="none"){
					$("#basketItemsWrap").show();
					$("#search_blox").css("height","141px");
					$("#search_blox_bottom_arrow").css("display","none");
				}  
			}
		});
	}
}

function delete_value(link,id,value2,obj){
	$.ajax({
		url : link,
		data : { delete_value:id,value2:value2},
		type : 'post',
		success : function(msg){
			$('#prod_'+id).remove();
			var temp = $('#basketItemsWrap #basketcount').html();
			if(temp != 0){
				temp--;
				$('#basketItemsWrap #basketcount').html(temp);
				count_items1--;
				if(count_items1 == 0){
					$("#empty_basket_msg2").show();
					$("#print_bigbtn1").remove();
				}
			}
			if(temp == 0){
				$("#basketItemsWrap").css("display","none")
				$("#search_blox").css("height","96px");
				$("#search_blox_bottom_arrow").show();
			}
			//console.log(count_items);
			//console.log(count_items1);
		}
	});
}
function del_value(link,id,value2,value3,obj){
	$.ajax({
		url : link,
		data : { delete_value:id,value2:value2,value3:value3},
		type : 'post',
		success : function(msg){
			$('#prod_'+value3+'_1').remove();
			var temp = $('#basketItemsWrap #basketcount').html();	
			if(temp != 0){
				temp--;
				$('#basketItemsWrap #basketcount').html(temp);
				count_items--;
				if(count_items == 0){
					$("#empty_basket_msg").show();
					$("#print_bigbtn").remove();
				}
			}
			if(temp == 0){
				$("#basketItemsWrap").css("display","none")
				$("#search_blox").css("height","96px");
				$("#search_blox_bottom_arrow").show();
			}
			//console.log(count_items);
			//console.log(count_items1);
		}
	});
}

function timedRefresh(timeoutPeriod) {
	setTimeout("location.reload(true);",timeoutPeriod);
}

