﻿var animate = "true";

$( document ).ready( function() {
  childNumberEqual0();
  activateHighlights();
  setTimeout( resizableMenu , 1500 );
  copyVarEmailToNewsletter();
  addClassPostform1();

} );

function childNumberEqual0(){
  $("#win-xp3 .selectedTxt").text("0");
}

function addClassPostform1(){
  $('form[name="postform1"]').find('input[type="button"]').addClass("postform1Button");
}

function copyVarEmailToNewsletter() {
  if ( $( 'input[name*="emailField"]' ).val() == "<!--@Server:Request.footernewsletter-->" ) {
  }
  else {
    $( 'input[name*="AccessUserEmail"]' ).val( $( 'input[name*="emailField"]' ).val() );
  }
}

function validateNewsletter(parId) {

  var submitForm = true,
      input = $( "#AccessUserEmail_" + parId ).val(),
      input2 = $( "#AccessUserName_" + parId ).val(),
      messageRequiredMail = $( "#requiredAccessUserEmail_" + parId ).text(),
      messageAcessMail = $( "#correctAccessUserEmail_" + parId ).text(),
      messageName = $( "#requiredAccessUserName_" + parId ).text();

  if ( input2 == '' ) {
    alert( messageName );
    submitForm = false;
  }
  if ( input == '' ) {
    alert( messageRequiredMail );
    submitForm = false;
  }
  else if ( validateEmail( input ) == 0 ) {
    alert( messageAcessMail );
    submitForm = false;
  }
  return submitForm;
}



function activateHighlights() {
  $( "#news li img" ).hover(

      function() {
        $( this ).parent().next().stop().animate( {"left": "221px"} , "slow" );
      } ,
      function() {
        $( this ).parent().next().stop().animate( {"left": "68px"} , "slow" );
      } );
  $( "a.btNews" ).hover(
      function() {
        $( this ).prev().stop().animate( {"left": "221px"} , "slow" );
      } ,
      function() {
        $( this ).prev().stop().animate( {"left": "68px"} , "slow" );
      } );
}

/* resets the general search box text to its default value */
function checkIfEmpty(input , defaultValue) {
  if ( ( $( '#' + input ).val() == "" ) || $( '#' + input ).val().toLowerCase() == defaultValue.toLowerCase() )
    $( '#' + input ).val( defaultValue );
}


/* clears the general search box text */
function clearField(input , defaultValue , type) {
  if ( ( $( '#' + input ).val() == "" ) || ( $( '#' + input ).val().toLowerCase() == defaultValue.toLowerCase() ) ) {
    $( '#' + input ).val( "" );
  }
}

//////////////////////////////////

function createGallery(path , destination , type) {
  path = path.substring( 0 , path.lastIndexOf( "/" ) );
  $.ajax( {
    url: location.protocol + "//" + location.hostname + "/Files/GetFolderContents.aspx?Path=" + path,
    success: function(data) {
      var xml,
          imgNumbers = '',
          allImgSrc = '';
      if ( $.browser.msie && typeof data == "string" ) {
        xml = new ActiveXObject( "Microsoft.XMLDOM" );
        xml.async = false;
        xml.loadXML( data );
      }
      else {
        xml = data;
      }

      if ( type == "imageGallery" ) {
        $( xml ).find( "File" ).each( function() {
          //allImgSrc += '<span><a href="javascript:void(0)" style="background-image:url(/admin/public/getimage.aspx?Image=' + $(this).attr('href') + '&height=80)"><img src="/admin/public/getimage.aspx?Image=' + $(this).attr('href') + '&height=80" alt="' + $(this).attr('title') + '" /></a></span>';
          //          allImgSrc += '<span><img src="/admin/public/getimage.aspx?Image=' + $( this ).attr( 'href' ) + '&height=80" alt="' + $( this ).attr( 'title' ) + '" /><a href="' + $( this ).attr( 'href' ) + '" rel="lightbox">&nbsp;</a></span>';
          // LAST         allImgSrc += '<span><img src="/admin/public/getimage.aspx?Image=' + $( this ).attr( 'href' ) + '&height=80" alt="' + $( this ).attr( 'title' ) + '" /><a href="' + $( this ).attr( 'href' ) + '" title="' + $( this ).attr( "title" ) + '" rel="lightbox">&nbsp;</a></span>';
          allImgSrc += '<span><img src="/admin/public/getimage.aspx?Image=' + $( this ).attr( 'href' ) + '&height=80" alt="' + $( this ).attr( 'title' ) + '" /><a href="' + $( this ).attr( 'href' ) + '" rel="lightbox">&nbsp;</a></span>';
          //          allImgSrc += '<span><a href="'+$(this).attr('href')+'"><img src="/admin/public/getimage.aspx?Image=' + $(this).attr('href') + '&height=80" alt="' + $(this).attr('title') + '" />&nbsp;</a></span>';
        } );
        $( '#' + destination ).html( allImgSrc );


        $( "a[rel='lightbox']" ).colorbox( {
          slideshow:true,
          transition:"elastic",
          rel:'lightbox',
          slideShow: false
        } );

      }
      else {
        $( xml ).find( "File" ).each( function(i) {
          if ( i < 3 ) {
            allImgSrc += '<img src="/admin/public/getimage.aspx?Image=' + $( this ).attr( 'href' ) + '&width=290&height=420" alt="' + $( this ).attr( 'title' ) + '" />';
          }
        } );

        $( '#' + destination ).html( allImgSrc ).cycle( {
          speed: 2000,
          timeout: 7000
        } );

      }
    }
  } );
}

function createGalleryRooms(path , destination , type) {
  path = path.substring( 0 , path.lastIndexOf( "/" ) );
  $.ajax( {
    url: location.protocol + "//" + location.hostname + "/Files/GetFolderContents.aspx?Path=" + path,
    success: function(data) {
      var xml,
          imgNumbers = '',
          allImgSrc = '';
      if ( $.browser.msie && typeof data == "string" ) {
        xml = new ActiveXObject( "Microsoft.XMLDOM" );
        xml.async = false;
        xml.loadXML( data );
      }
      else {
        xml = data;
      }

      if ( type == "rooms" ) {

        $( xml ).find( "File" ).each( function(i) {
          if ( i < 3 ) {
            allImgSrc += '<img src="/admin/public/getimage.aspx?Image=' + $( this ).attr( 'href' ) + '&width=980&height=421&Resolution=75&Compression=50" alt="' + $( this ).attr( 'title' ) + '" />';
          }
        } );            

        setTimeout(function(){
          $( '#' + destination ).css("visibility","visible");
        },1500);

        $( '#' + destination ).html( allImgSrc ).cycle( {
          speed: 2000,
          timeout: 4500
        } );



      }
      else {
        $( xml ).find( "File" ).each( function(i) {
          if ( i < 3 ) {
            allImgSrc += '<img src="/admin/public/getimage.aspx?Image=' + $( this ).attr( 'href' ) + '&width=980&height=500&Resolution=75&Compression=50" alt="' + $( this ).attr( 'title' ) + '" />';
          }
        } );


        setTimeout(function(){
          $( '#' + destination ).css("visibility","visible")
        },1500);

        $( '#' + destination ).html( allImgSrc ).cycle( {
          speed: 2000,
          timeout: 7000
        } );

        $("#center").css("background","none");

      }
    }
  } );
}





function createSubMenus(parId) {
  var paragraphHeaders = $( "div.paragraphHeader" ).length,
      subMenu = '<ul id="subMenu">';

  $( "div.paragraphHeader" ).each( function(i) {
    subMenu += '<li id="link_' + $(this).parent().attr("id") + '"><a href="javascript:void(0)" onclick="updateParagraph(' + i + ')">' + $( this ).text() + '</a></li>';
  } );

  if ( paragraphHeaders > 1 ) {
    subMenu += '</ul>';
    $( "#center" ).prepend( subMenu );
    if ( $( "#content" ).hasClass( "rooms" ) ) {
      $( "#center" ).addClass( "withSubMenu" );
      if ( $( '.killSpan' ).text() == "aa" ) {
        $( "#subMenu" ).css( "display" , "none" );
      }
    }
    else {

      if ( parId == "" ) {
        $( "#subMenu a:first" ).trigger( "click" );
      }
      else {
        $( '#link_parag_'+ parId + ' a' ).trigger( "click" );

      }
      $( "#center" ).addClass( "withSubMenu" );
      if ( $( '.killSpan' ).text() == "aa" ) {
        $( "#subMenu" ).css( "display" , "none" );
      }
    }
  }

}

function createHighlights() {

  var num = 0;

  $( ".seeMoreText:last" ).removeClass().addClass( "seeMoreText seeMoreText0" );
  $( ".numPagination:last a" ).attr( 'id' , 'highlight_0' );

  $( ".numPagination a" ).each( function() {
    if ( num == 0 ) {
      $( this ).addClass( "select" )
    }
    $( this ).attr( "href" , "javascript: thisisit(" + num + ")" );
    num++;
  } );

  $( '.seeMoreButton' ).click( function() {
    if ( animate ) {
      $( this ).text( closeTextTranslate ).css( "backgroundImage" , "url('/Files/System/QBV/images/close_hp.gif')" );
      $( ".seeMoreText" + cur ).animate( {"right": "0"} , "slow" );
      window.clearInterval( timi );
      timi = null;
      animate = false;
    }
    else {
      $( this ).text( seeMoreTextTranslate ).css( "backgroundImage" , "url('/Files/System/QBV/images/see_back.jpg')" );
      $( ".seeMoreText" + cur ).animate( {"right": "-290"} , "slow" );
      animate = true;
      timi = window.setInterval( 'doslide()' , 5000 );
    }
  } );

  $( ".numPagination a" ).click( function() {
    if ( animate ) {
      window.clearInterval( timi );
      timi = null;
    }
    else {

      var numHighlightID = $( this ).attr( "id" );
      var numHighlight = numHighlightID.replace( /^.+_/ , "" );

      $( ".seeMoreText" + cur ).animate( {"right": "-290"} , "slow" );
      $( ".seeMoreText" + numHighlight ).animate( {"right": "0"} , "slow" );
    }

  } )

}

function closeRoom() {

  var animateRoom = 1;
  
  $( ".seeMoreButtonRoom" ).click( function() {
    if ( animateRoom ) {
      $( ".rooms" ).animate( {"left": "-361"} , "slow" );
      $( this ).text( seeMoreTextTranslate ).css( "backgroundImage" , "url('/Files/System/QBV/images/see_back.jpg')" );
      animateRoom = 0;
    }
    else {
      $( ".rooms" ).animate( {"left": "0"} , "slow" );
      $( this ).text( closeTextTranslate ).css( "backgroundImage" , "url('/Files/System/QBV/images/close_hp.gif')" );
      animateRoom = 1;
    }
  } )
}


function resizableMenu() {
//  var totalWidth = $( '#mainMenu' ).width(),
  var totalWidth = 955,
      numItens = $( ".pageLevel1 li" ).length,
      freeSpace = 0, totalLiWidth = 0,
      spacingLeft = 0, spacingRight = 0;


  $( ".pageLevel1 li" ).each( function() {
    totalLiWidth += $( this ).outerWidth( true );
  } );

  freeSpace = totalWidth - totalLiWidth;
  spacingLeft = Math.floor( freeSpace / numItens / 2 );
  spacingRight = spacingLeft;

  $( ".pageLevel1 li a" ).each( function(i) {
    if ( i == (numItens - 1) ) {
      spacingLeft = Math.floor( freeSpace / 2 );
      spacingRight = Math.ceil( freeSpace / 2 );
    }
    freeSpace -= (spacingLeft + spacingRight);
    $( this ).css( {
      'padding-left' : spacingLeft + 'px',
      'padding-right' : spacingRight + 'px'
    } );
  } );

  $("#mainMenu ul").css("visibility","visible");
}


function roomGallery(idLink) {
  var pathRoom = $( ".imgLink:eq(" + idLink + ")" ).text();
  var pathRoomGallery = pathRoom.replace( /[^\/]*$/ , "" );
  createGalleryRooms( pathRoomGallery , "imagesContentRoom" , "rooms" );
}

function updateParagraph(index) {

  var widthSubmenu = $("#subMenu").width(),
      marginLeftSubmenu = 970 - widthSubmenu;


  if ( $( "#content" ).hasClass( "rooms" ) ) {


    $("#imagesContentRoom").css("visibility","hidden");

    $( ".rooms" ).animate( {"left": "0"} , "slow" );
	  $( "ul#subMenu" ).animate( {"margin-left": marginLeftSubmenu} , "slow" );
    $( ".containerRoom" ).animate( {"left":"9"} , "slow" );

    if ( $( ".seeMoreButtonRoom" ).text() == seeMoreTextTranslate ) {
      $( ".seeMoreButtonRoom" ).click();
    }


    roomGallery( index );

    $( "#content .paragraph" ).slideUp( 'slow' );
    $( "#center li" ).removeClass( "activeSub" );
    $( "#content .paragraph:eq(" + index + ")" ).slideDown( 'slow' );
    $( "#center li:eq(" + index + ")" ).addClass( "activeSub" );

  }
  else {
    $( "#content .paragraph" ).slideUp( 'slow' );
    $( "#center li" ).removeClass( "activeSub" );
    $( "#content .paragraph:eq(" + index + ")" ).slideDown( 'slow' );
    $( "#center li:eq(" + index + ")" ).addClass( "activeSub" );
  }
}

function ValidateSearch(errorMessage , defaultValue) {
  if ( ( $( ".footerNewsletter" ).val() == '' ) || ( $( ".footerNewsletter" ).val().toLowerCase() == defaultValue.toLowerCase() ) ) {
    alert( errorMessage );
    return false;
  }
}

