var badBrowser;
var pixel = new Image();

if( window.location.pathname.replace("/test", "").split("/").length == 3 ) {
   pixel.src = "../images/pixel.gif";
} else {
   pixel.src = "images/pixel.gif";
}

$(document).ready(function() {
   $( "#navigation_services a img" ).mouseover( switchOn );
   $( "#navigation_services a img" ).mouseout( switchOff );

   $( "input[type=text], input[type=password], select, textarea" ).focus( function(){ $(this).css( "color", "#000000" ); } );

   $( "li.dropdown" ).hover( function() { $( "ul", this ).css( "display", "block" ); },
                             function() { $( "ul", this ).css( "display", "none" ); } )

   badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");

   if( badBrowser ) {
      // get all pngs
      $( "img[src$=.png]" ).each( function() {
         if( !this.complete ) {
            this.onload = function() { fixPng( this ) };
         } else {
            fixPng( this );
         }
      } );

      $( ".background_png" ).each( function() {
         fixPngBackground( this );
		} );

      $( "li" ).each( function() {
         backgroundImg = $( this ).css( "background-image" );

         if( backgroundImg.indexOf( "arrow_orange.png" ) != -1 ) {
            src = backgroundImg.replace( 'url("', '' ).replace( '")', '' );
            $( this ).css( "background-image", "none" );
            $( this ).css( "height", "10px" );

            // set filter ( display original image )
            this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='crop')";
         }
		} );

   }
} );

function fixPng( png ) {
   var src = png.src;
   if( !png.style.width ) { png.style.width = $( png ).width(); }
   if( !png.style.height ) { png.style.height = $( png ).height(); }
   
   // replace by pixel image
   png.onload = function() { };
   png.src = pixel.src;

   // set filter ( display original image )
   png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
}

function fixPngBackground( element ) {
   backgroundImg = $( element ).css( "background-image" );

   if( backgroundImg.indexOf( ".png" ) != -1 ) {
      src = backgroundImg.replace( 'url("', '' ).replace( '")', '' );
      $( element ).css( "background-image", "none" );

      // set filter ( display original image )
      element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
   }
}

function switchOff() {
   if( badBrowser && ( this.src.indexOf( "pixel.gif" ) > -1 ) ) {
      newSrc = this.filters.item( "DXImageTransform.Microsoft.AlphaImageLoader").src.replace( "_on", "_off" );
      this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + newSrc + "',sizingMethod='scale')";
   }
   else {
      this.src = this.src.replace( "_on", "_off" );
   }
}

function switchOn() {
   if( badBrowser && ( this.src.indexOf( "pixel.gif" ) > -1 ) ) {
      newSrc = this.filters.item( "DXImageTransform.Microsoft.AlphaImageLoader").src.replace( "_off", "_on" );
      this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + newSrc + "',sizingMethod='scale')";
   }
   else {
      this.src = this.src.replace( "_off", "_on" );
   }
}
