function findPos(obj) {
	var curleft = curtop = 0;
	if ( obj && obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

var nr_ie = 0;
var c_width = 0;
var c_height = 0;
var isOnCat = 0;



$(function()
{
	$("#searchForm1").submit(function(){
			var t = $("#searchText1");
			if( t.val() == "" ){
				alert("Introduceti cuvantul cautat");
				t.focus();
				return false;
			};
		});
	$("#prodlist250").click(function(){
		var t = jQuery(this);
		if( t.hasClass("h") ){
			isOnCat = 0;
			hideMyCats(250);
		}
		else{
			showMyCats(250);
		}
		return false;
	});
	$("#prodlist271").click(function(){
		var t = jQuery(this);
		if( t.hasClass("h") ){
			isOnCat = 0;
			hideMyCats(271);
		}
		else{
			showMyCats(271);
		}
		return false;
	});
	$("#prodlist266").click(function(){
		var t = jQuery(this);
		if( t.hasClass("h") ){
			isOnCat = 0;
			hideMyCats(266);
		}
		else{
			showMyCats(266);
		}
		return false;
	});
	$("#prodlist249").click(function(){
		var t = jQuery(this);
		if( t.hasClass("h") ){
			isOnCat = 0;
			hideMyCats(249);
		}
		else{
			showMyCats(249);
		}
		return false;
	});
	$("#prodlist249").hover(
		function(){
			//do nothing...
		},
		function(){
			setTimeout("hideMyCats(249)", 500);
		}
	);
	$("#prodlist266").hover(
		function(){
			//do nothing...
		},
		function(){
			setTimeout("hideMyCats(266)", 500);
		}
	);
	$("#prodlist271").hover(
		function(){
			//do nothing...
		},
		function(){
			setTimeout("hideMyCats(271)", 500);
		}
	);
	$("#prodlist250").hover(
		function(){
			//do nothing...
		},
		function(){
			setTimeout("hideMyCats(250)", 500);
		}
	);
	//$("#lista").css("opacity", "0");
	$("#lista250").hover(
		function(){
			isOnCat = 1;
		},
		function(){
			isOnCat = 0;
			hideMyCatsT();
			setTimeout("hideMyCats(250)", 500);
		}
	);
	$("#lista271").hover(
		function(){
			isOnCat = 1;
		},
		function(){
			isOnCat = 0;
			hideMyCatsT();
			setTimeout("hideMyCats(271)", 500);
		}
	);
	$("#lista266").hover(
		function(){
			isOnCat = 1;
		},
		function(){
			isOnCat = 0;
			hideMyCatsT();
			setTimeout("hideMyCats(266)", 500);
		}
	);
$("#lista249").hover(
		function(){
			isOnCat = 1;
		},
		function(){
			isOnCat = 0;
			hideMyCatsT();
			setTimeout("hideMyCats(249)", 500);
		}
	);

	//fancy
	
	$("a#activate_custom_1").click(function(){
		$("a#custom_1").click();
		return false;
	});

	$(".sharelinks a.share").click(function(){

		 if ($(this).hasClass("emailfr")){
			$("a#custom_friend").click();
			return false;
		 }else{
			 if ($(this).hasClass("yahoo")){
				var name=prompt("Introduceti id-ul prietenului:","");
				if (name!=null && name!=""){
						var thishref=$(this).attr("rel");
						$(this).attr("href","ymsgr:sendIM?"+name+"&m="+thishref);
				  }else{alert("Id-ul prietenullui este obligatoriu!");return false;}
			 }
		 }
	 });


});

 function getGroupItems(opts) {
		 jQuery.each(imageList, function(i, val) {
		 opts.itemArray.push(val);
		 });
}

function hideMyCatsT(){
}

function hideMyCats(cat){
	if( isOnCat == 1 ) return ;
	
	if ($.browser.msie)
		{
			if ($.browser.version.number > 6)
				{
					$("#lista"+cat).stop().animate({"opacity": "0"}, 500, function(){  $("#lista"+cat).css("display", "none"); });
				}
				else 
				{
					$("#lista"+cat).css("display", "none");
				}
		}
		else {$("#lista"+cat).stop().animate({"opacity": "0"}, 500, function(){  $("#lista"+cat).css("display", "none"); });}
	$("#prodlist"+cat).removeClass("h");
	isOnCat = 0;
}
function showMyCats(cat){
	
	if ($.browser.msie)
		{
			if ($.browser.version.number > 6)
				{
					$("#lista"+cat).stop().css("display", "block").animate({"opacity": 1}, 500);
				}
				else 
				{
					$("#lista"+cat).css("display", "block");
				}
		}
		else {$("#lista"+cat).stop().css("display", "block").animate({"opacity": 1}, 500);}


	
	
	$("#prodlist"+cat).addClass("h");
}

jQuery.fn.newsletter = function(){
return this.each(function (){
	 var t = jQuery(this);
	 t.submit(function(){
		 if( checkEmailAddress( document.getElementById( $("#"+t.attr("id")+ " input[name='newsemail']:first" ).attr("id") ), 'Y' ) == false ){
			 return false;
		 }
	 });
});
}

jQuery.fn.hint = function () {
  return this.each(function (){
    /* get jQuery version of 'this'*/
    var t = jQuery(this); 
    /* get it once since it won't change*/
    var title = t.attr('alt'); 
    /* only apply logic if the element has the attribute*/
    if (title) { 
      /* on blur, set value to title attr if text is blank*/
      t.blur(function (){
        if ($.trim(t.val()) == '') {
          t.val(title);
        }
      });
      /* on focus, set value to blank if current value */
      /* matches title attr*/
      t.focus(function (){
        if (t.val() == title) {
          t.val('');
        }
      });

      /* clear the pre-defined text when form is submitted*/
      t.parents('form:first()').submit(function(){
          if (t.val() == title) {
              t.val('');
          }
      });

      /* now change all inputs to title */
      t.blur();
    }
  });
}

$(function()
{
	$('input:text').hint();

	$("#newsletteremail").submit(function(){
		var t = $("#searchEmail");
		if( t.val() == "" ){
			alert("Introduceti o adresa de email");
			t.focus();
			return false;
		};
	});
	$("#searchForm2").submit(function(){
		var t = $("#searchText2");
		if( t.val() == "" ){
			alert("Introduceti cuvantul cautat");
			t.focus();
			return false;
		};
		window.location = $("#searchForm2").attr("action") + "?q=" + t.val();
		return false;
	});
	$("#arataToate").click(function(){
		var t = jQuery(this);
		if( t.hasClass("h") ){
			isOnCat = 0;
			hideMyCats();
		}
		else{
			showMyCats();
		}
		return false;
	});
	$("#arataToate").hover(
		function(){
			//do nothing...
		},
		function(){
			setTimeout("hideMyCats()", 500);
		}
	);
	if ( $.browser.msie ){
		$('input:checkbox').css('border', 'none');
		$('input:radio').css('border', 'none');
	}
	 var optiuni = {
        resizeLgImages:     true,
        displayNav:         true,
        handleUnsupported:  'remove',
        keysClose:          ['c', 27] // c or esc
    };

});

function changeSortType(x)
{
//var x = document.getElementById("selectSortType");
var unde = x.options[x.selectedIndex].value;
window.location = xcart_web_dir + "/" + unde;
}

function gabi_repair_bug_variant_avail()
{
	//alert("intru in functie: " + parseInt(document.getElementById('product_avail_txt').innerHTML) );
	if( document.getElementById('product_avail') )
	{
		if( parseInt(document.getElementById('product_avail').options[0].value) >= min_avail ) doIsAvailable();
		else doNotAvailable();
	}
}
function checkAvail()
{
	gabi_repair_bug_variant_avail();
}
function doNotAvailable()
{
	//alert("Nu e disponibil");
	var notVisible = "notVisible";

	//document.getElementById('txt_produs_avail').setAttribute("class", "txt_produs_avail_not_ok");
	//document.getElementById('txt_produs_avail').setAttribute("className", "txt_produs_avail_not_ok"); // for ie

	$("#product_avvail").removeClass("ch_avail");
	$("#product_avvail").addClass("ch_unavail");
	$("#product_avvail").html(txt_out_of_stock);
	//functions defined in myScripts.js
	clearAllElem(document.getElementById("product_avail"));
	var elem = document.createElement('option');
	elem.value = "0";
	elem.text = txt_out_of_stock;//defined by xcart
	addSelectElem(document.getElementById("product_avail"), elem);


	return true;
}
function doIsAvailable()
{
	//alert("E disponibil");
	var notVisible = "notVisible";
	$("#product_avvail").removeClass("ch_unavail");
	$("#product_avvail").addClass("ch_avail");
	$("#product_avvail").html(is_in_stoc);
	return true;
}
function clearAllElem(select)
{
select.options.length = 0;
}
function addSelectElem(select, elem)
{
try
{
select.add(elem,null);
}
catch (ex)
{
select.add(elem);
}
}


