var closetimer = 0;
var sel_init = 0;

function ig(img,div){
	$('#'+div).attr('href', 'images/large/'+img+'.jpg');
	$('#'+div+' > img').attr('src', 'images/middle/'+img+'.jpg');			
}


function jm_close(){
	$("#oferta_a").hide();
	$("#oferta_e").hide();
}
	
function jm_open(timeout){
	closetimer = window.setTimeout(jm_close, timeout);
}
	
function jm_cancel(){
	if(closetimer){
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}


jQuery(document).ready(function(){

        $(".select").click(function(){
	    $('.items').hide();
            if(sel_init == 0){
                var items = $(this).find('.items');
                items.show();
                items.css('left', $(this).offset().left - 30);
                items.css('top', $(this).offset().top - 20);
                sel_init++;
            }
        });

        $(".spcselect").click(function(){
            $('.items').hide();
	    if(sel_init == 0){
                var items = $(this).find('.items');
                items.show();
                items.css('left', $(this).offset().left - 100);
                items.css('top', $(this).offset().top - 20);
                sel_init++;
            }
        });

        $(".items").click(function(){
            $(this).hide();
            sel_init--;
        });

        $("html").click(function(){
            if(sel_init == 0){
                $('.items').hide();
            } else { sel_init--; }
        });

	$('.outlets_list').change(function(){
		if(this.value){
			location.href = this.value;
		}
	});
	
	$("#oferta_a").mouseover(function(e){
		jm_cancel();		
	});

	$("#oferta_e").mouseover(function(e){
		jm_cancel();
	});
	
	$("#oferta_e").mouseout(function(e){		
		jm_open(1000);		
	});

   $("#oferta").mouseover(function(e){      
       
       	var mPos = $('#navi').offset();
       	var mWidth = $('#navi').outerWidth();
       
       	var eWidth = $('#oferta_e').outerWidth();
		var fPos = (mPos.left + mWidth) - eWidth;

		var pos = $('#oferta').offset();    
        var width = $('#oferta').outerWidth();
       	
        var left = fPos;
        var top = pos.top;

        $("#oferta_a").css("top", (top+32) + 'px');
      	$("#oferta_a").css("left", (pos.left+(width/2)-23) + 'px');      	
      	$("#oferta_a").show();
      
     	$("#oferta_e").css("top", (top+32) + 'px');
      	$("#oferta_e").css("left", fPos + 'px');
      	$("#oferta_e").show();

      	jm_open(2000);
   }); 
})

function showCountryList(whichLayer)
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}
