$(document).ready(function(){
   //Hover offsets
  xOffset = 30;
  yOffset = 30;
  $(".blueBtn").append('<span class="downarrowframe"><span class="downarrow"></span></span>');
  
  //check hover
  $(".blueBtn").hover(function(e){
    
    if($('#dropdown').length>0){
      //alert("a");
    } else {


      $('.blueBtn')
        .css("-moz-border-radius-bottomright", "0px")
        .css("-webkit-border-radius-bottomright", "0px")
        .css("-khtml-border-radius-bottomright", "0px")
        .css("border-bottom-right-radius", "0px");
      //$("body").append("<div id='dropdown'><div></div><div><A href='http://www.inwise.ro'>Romania</a></div><div><A href='http://www.inwise-nl.com'>Netherlands</a></div><div><A href='http://www.inwise.com/tr'>Turkey </a></div><div><A href='http://www.inwise.com/ng'>Nigeria </a></div><div><A href='http://www.inwise.es '>Spain </a></div><div><A href='http://www.inwise.be'> France, Belgium & Luxemburg</a></div><div><A href='http://www.inwise.co.il'>Israel</a></div></div>");
      $("body").append("<div id='dropdown'><div></div><div><A href='http://www.inwise.ro'>Romania</a></div><div><A href='http://www.inwise-nl.com'>Netherlands</a></div><div><A href='http://www.inwise.es '>Spain </a></div><div><A href='http://www.inwise.be'> France, Belgium & Luxemburg</a></div><div><A href='http://www.inwise.co.il'>Israel</a></div></div>");
      var sourceposition=$(".blueBtn").position();
      var SourceHeight=$(".blueBtn").height();
      var SourceWidth=$(".blueBtn").outerWidth();
      var sourceTop=sourceposition.top;
      SourceWidth=SourceWidth-10;
            if (navigator.appName == 'Microsoft Internet Explorer') {
              var ua = navigator.userAgent;
var ver = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (ver.exec(ua) != null)
          ver  = parseFloat( RegExp.$1 );
        if ( ver > -1 ) {
          if ( ver <= 8 ) {
            sourceTop=sourceTop + 17;
          } else {
            $('.blueBtn').animate({backgroundColor: '#58595B'});
          }
        }
      } else {
        $('.blueBtn').animate({backgroundColor: '#58595B'}); 
        sourceTop=sourceTop + SourceHeight;
      }   
      $("#dropdown")
        .css("top",(sourceTop) + "px")
        .css("left",(sourceposition.left) + "px")
        .css("position","absolute")
        .css("height",SourceHeight)
        
        .fadeIn("slow");
      $("#dropdown").animate({height: "100%"}, 2500 );
      $('#dropdown').find("div")
        .css("display","block")
        .css("width",SourceWidth)
        .css("color","white")
        .css("text-align","center")
        .css("font","bold 12px/20px Arial")
        .css("padding","6px 5px 6px 5px")
        .css("background-color","#00B4CB");
       if (navigator.appName == 'Microsoft Internet Explorer') {
    if ( ver > -1 ) {
      if ( ver <= 7 ) {
        SourceWidth=SourceWidth-2;
           $('#dropdown').find("div").css("width",SourceWidth)
      }
      
    }
             }

    
      $('#dropdown').find("div").find("a")
        .css("color","#ffffff")
        .css("text-decoration","none")
        .css("display","block")
        .css("font","bold 12px/20px Arial");
      $('#dropdown').find("div:first")
        .css("height","0.5px");
      //  .css("border-bottom","1px solid #ffffff");
      $('#dropdown').find("div:last")
        .css("-moz-border-radius-bottomright", "5px")
        .css("-moz-border-radius-bottomleft", "5px")
        .css("-webkit-border-radius-bottomright", "5px")
        .css("-webkit-border-radius-bottomleft", "5px")
        .css("-khtml-border-radius-bottomright", "5px")
        .css("-khtml-border-radius-bottomleft", "5px")
        .css("border-bottom-right-radius", "5px")
        .css("border-bottom-left-radius", "5px");
      $('#dropdown div').hover(function(e){     
        $(this).find("a").animate({color: '#EBE4E5'});
                               },function(e){
       
        $(this).find("a").animate({color: '#ffffff'});       
                               }                    
                              
                              );
   }
  });
  //check if mouse is out
   $(document).mousemove(function(e){
    if ($('#dropdown').length>0) {
       
      var sourceposition=$(".blueBtn").position();
      var sourcewidth=$("#dropdown").width();
      var sourceheight=$("#dropdown").height();
      if(e.pageY <sourceposition.top || e.pageY > (sourceposition.top + sourceheight+yOffset) || e.pageX > (sourceposition.left + sourcewidth + xOffset ) || e.pageX <(sourceposition.left-xOffset )){ 
$('#dropdown').remove();
        $('.blueBtn').animate({backgroundColor: '#00B4CB'});
             $('.blueBtn')
        .css("-moz-border-radius-bottomright", "5px")
        .css("-webkit-border-radius-bottomright", "5px")
        .css("-khtml-border-radius-bottomright", "5px")
        .css("border-bottom-right-radius", "5px");
      }     
    } 
  });
  
  });

