$( document ).ready(
  function(){

    img1 = new Image();
    img1.src = "../images/loading.gif";
    
    var zIndexNumber = 1000;
    
    $('li').each(
      function() {
        $(this).css('zIndex', zIndexNumber);
        zIndexNumber -= 10;
      }
    );
  
    $( ".airtime-area" ).hide();

    $( ".rollover" ).hover(
      function(){
        var fileExtension = $( this ).attr( "src" ).substr( $( this ).attr( "src" ).lastIndexOf( "." ) );
        $( this ).attr( "src", $( this ).attr( "src" ).replace( fileExtension, "-over" + fileExtension ) );
      },
      function(){
        $( this ).attr( "src", $( this ).attr( "src" ).split("-over" + ".").join( "." ) );
      }
    );
    
    $( ".show-costs a" ).hover(
      function(){
        $( ".airtime-show-cost, .sms-show-cost" ).each(
          function( n ){
            var value = $( this ).html();
            value = value.substring( 1, value.length );
            $( this ).html( "R" + ( value * 0.95 ).toFixed(2) );
          }
        );
        $( ".elec-show-cost" ).each(
          function( n ){
            var value = $( this ).html();
            value = value.substring( 1, value.length );
            $( this ).html( "R" + ( value * 0.99 ).toFixed(2) );
          }
        );
        $( ".netsaver-show-cost" ).each(
          function( n ){
            var value = $( this ).html();
            value = value.substring( 1, value.length );
            $( this ).html( "R" + ( value * 1.00 ).toFixed(2) );
          }
        );
      },
      function(){
        $( ".airtime-show-cost, .sms-show-cost" ).each(
          function( n ){
            var value = $( this ).html();
            value = value.substring( 1, value.length );
            $( this ).html( "R" + ( value / 0.95 ).toFixed(0) );
          }
        );
        $( ".elec-show-cost" ).each(
          function( n ){
            var value = $( this ).html();
            value = value.substring( 1, value.length );
            $( this ).html( "R" + ( value / 0.99 ).toFixed(0) );
          }
        );
        $( ".netsaver-show-cost" ).each(
          function( n ){
            var value = $( this ).html();
            value = value.substring( 1, value.length );
            $( this ).html( "R" + ( value / 1.00 ).toFixed(0) );
          }
        );
      }
    );

    $( ".network-link, .button" ).click(
      function(){
        var network = $( this ).text().toLowerCase();

        if( network == "virgin" ){ network = "branson"; }
        if( network == "cell c" ){ network = "cellc"; }
        if( network == "8.ta" ){ network = "heita"; }
        if( network == "netsaver handset" ){ network = "netsaverhandset"; }

        var checkElement = $( "#"+ network );

        if( $( ".airtime-area:visible" ) ){
          checkID = $( ".airtime-area:visible" ).attr( "id" );
        }

        if( $( ".airtime-area" ).is( ":visible" ) ){
          $( ".airtime-area" ).slideUp( "normal" );
          if( !( checkID == network ) ) {
            $( "#" + network ).slideDown( "normal" );
          }
          return false;
        }

        if( ( checkElement.is( "#" + network ) ) && ( !checkElement.is( ":visible" ) ) ){
          $( "#" + network ).slideUp( "normal" );
          checkElement.slideDown( "normal" );
          return false;
        }
      }
    );
    
    $( "#buy-now" ).click(
      function(){
        if( !$( ".airtime-area" ).is( ":visible" ) ) {
          $( "#vodacom" ).slideDown( "normal" );
        }
      }
    );

    $( ".confirm-order-button2" ).click(
      function(){
        $( ".confirm-order-button2" ).hide( );
      }
    );
    
    $( ".airtime-button, .sms-button, .netsaver-button" ).click( 
      function(){
        $( ".airtime-buttons-area" ).mask( "Loading..." );
      }
    );

  }
);

function closeEskom( ){
  $( "#eskom" ).slideUp( "normal" );
}
  
function win(){
  window.open( "terms.html", "Window1", "menubar=no, width=420, height=600, toolbar=no" );
}

function win2(){
  window.open( "terms-ship.html", "Window1", "menubar=no, width=700, height=500, toolbar=no" );
}

