/*
var curSel = null;
var outSel = false;
var curSelIndx = -1;
*/
menu_item_1= new Image();
menu_item_1.src="/views/images/menu_item_txt_red_1.png";
menu_item_2= new Image();
menu_item_2.src="/views/images/menu_item_txt_red_2.png";
menu_item_3= new Image();
menu_item_3.src="/views/images/menu_item_txt_red_3.png";
menu_item_4= new Image();
menu_item_4.src="/views/images/menu_item_txt_red_4.png";
menu_item_5= new Image();
menu_item_5.src="/views/images/menu_item_txt_red_5.png";
menu_item_6= new Image();
menu_item_6.src="/views/images/menu_item_txt_red_6.png";


/* Main manu images */
$(document).ready(function() {

	$('#item_txt1').mouseover(function() {
		$('#item_txt1').hide('');
		$('#item_image1').show('');
		return false;
	});

	$('#item_image1').mouseout(function() {
		$('#item_txt1').show('');
		$('#item_image1').hide('');
		return false;
	});

	$('#item_txt2').mouseover(function() {
		$('#item_txt2').hide('');
		$('#item_image2').show('');
		return false;
	});

	$('#item_image2').mouseout(function() {
		$('#item_txt2').show('');
		$('#item_image2').hide('');
		return false;
	});

	$('#item_txt3').mouseover(function() {
		$('#item_txt3').hide('');
		$('#item_image3').show('');
		return false;
	});

	$('#item_image3').mouseout(function() {
		$('#item_txt3').show('');
		$('#item_image3').hide('');
		return false;
	});

	$('#item_txt4').mouseover(function() {
		$('#item_txt4').hide('');
		$('#item_image4').show('');
		return false;
	});

	$('#item_image4').mouseout(function() {
		$('#item_txt4').show('');
		$('#item_image4').hide('');
		return false;
	});

	$('#item_txt5').mouseover(function() {
		$('#item_txt5').hide('');
		$('#item_image5').show('');
		return false;
	});

	$('#item_image5').mouseout(function() {
		$('#item_txt5').show('');
		$('#item_image5').hide('');
		return false;
	});

	$('#item_txt6').mouseover(function() {
		$('#item_txt6').hide('');
		$('#item_image6').show('');
		return false;
	});

	$('#item_image6').mouseout(function() {
		$('#item_txt6').show('');
		$('#item_image6').hide('');
		return false;
	});

	cart_get_count_item();

	alert_show();

    //find all select in the document 
    var slc = document.getElementsByTagName('select');
    for (var i=0; i<slc.length; i++) {
        //replase all select, that has DD list
        if (slc[i].size < 2) {
            var prnt = slc[i].parentNode;
            var tmp = prnt.innerHTML;
            var wd = slc[i].offsetWidth;
            var hg = slc[i].offsetHeight;


            //text for covering image
            var imgTxt = '<div id="sel_img_'+i+'" style="position: absolute; top: 0px; left:'+(wd-19)+'px; width: 19px; height: 26px; owerflow: hidden; text-indent: -9999em; background: transparent url(./images/sel_img.png) 0 0 no-repeat;">&nbsp;</div>';

            //text for drop down select
            var selTxt = '<select id="DD_sel_'+i+'" style="width:'+wd+'px; position: absolute; left: 0px; top:'+hg+'px; display: none;" size="20">';
            selTxt += slc[i].innerHTML;
            selTxt += '</select>';


            //modify the parent's innerHTML
            prnt.innerHTML = '<div style="width:'+wd+'px; height:'+hg+'px; position: relative;">'+tmp+imgTxt+selTxt+'</div>';

            slc[i].className = "repl_sel";

            //if we click on select, we must hide drop down select, if it shown
            slc[i].onclick = function() {
                try {
                    outSel = true;
                    document.onclick();
                } catch(err) {
                };
                outSel = false;

                return true;
            };


            //if we turn mouse out of covering image, we suppose that we out of the drop down box
            //if we do not set outSel = true; then drop down box will hide
            $('#sel_img_'+i).mouseout(function() {
                outSel = true;
            });

            $('#sel_img_'+i).mousedown(function(Event) {
				var prnt = $(this).parent().get()[0].getElementsByTagName('select')[0];            	
                var tmp = $(this).parent().get()[0].getElementsByTagName('select')[1];

                //if we click on other drop down image then we must hide DD box, if it shown
                try {
                    outSel = true;
                    document.onclick();
                } catch(err) {
                };
                outSel = false;

                //set up the parameters of the DD box
                tmp.style.display="inline";
                tmp.style.zIndex=100;
                //if we click on the free space, we must restore old value
                tmp.selectedIndex = prnt.selectedIndex;
                curSelIndx = tmp.selectedIndex;

                //set up the size of the DD box
                if (tmp.length > 20) {
                    tmp.size = 20+1;
                } else {
                    tmp.size = tmp.length+1;
//                    tmp.style.height = tmp.length*tmp.options[0].offsetHeight+2+'px';
                };
                var oh = 22; //this.parentNode.parentNode.getElementsByTagName('select')[0].offsetHeight()-4;
                tmp.style.height = (tmp.size-1)*oh+2+'px';


                //set up the parameters of showing the DD box: above or below se parent select
                if ((Event.screenY + tmp.offsetHeight) > screen.availHeight) {
                    tmp.style.top = -tmp.offsetHeight+'px';
                } else {
                    tmp.style.top = this.parentNode.parentNode.getElementsByTagName('select')[0].offsetHeight+'px';
                };

                //save the DDbox that has show
                curSel = tmp;

                //set up the parameters of the options, that inside the DDbox
                for (var i=0; i < tmp.length; i++) {
                    tmp.options[i].onmousemove = function(){
                        this.selected=true;
                    };
                    tmp.options[i].onclick = function(){
                        //tmp is the parent select
                        var tmp = this.parentNode.parentNode.getElementsByTagName('select')[0];
                       
                        tmp.selectedIndex = this.parentNode.selectedIndex;
                        tmp.onchange();
                    };
                }
               
                //id we click on DDbox we must hide it
                tmp.onclick = function() {
                    this.style.zIndex=0;
                    this.style.display='none';
                    outSel = false;
                };
                //follow the cursor position: inside or outside of the DDbox
                tmp.onmouseout = function() {
                    outSel = true;   
                }
                tmp.onmouseover = function() {
                    outSel = false;   
                }

                //id we click outside the DDbox we must hide it and restore old value in it
                document.onclick = function () {
                    if (outSel) {
                        curSel.style.zIndex=0;
                        curSel.style.display='none';
                        outSel = false;
                        curSel.selectedIndex = curSelIndx;

                        document.onclick = null;
                    }
                }



                return false;
            });

        }
    }



});



function updateSelects() {
    //find all select in the document 
    var slc = document.getElementsByTagName('select');
    for (var i=0; i<slc.length; i++) {
        //update all select, that are DD lists
        if (slc[i].id.substr(0, 6) == "DD_sel") {
 			var sel = $(slc[i]);
	 	    sel.html(sel.parent().children("select").html());	
        }
    }
}

