
  var t;
  var timeout_for_dragndrop;
  var new_content;
  var form_action_url;
  var ajax_url;
  var ajax_params;
  var last_opened_top_page_id = false;
  
  var visual_editor_contents = []
  visual_editor_contents[ 1 ] = '<p>Header content</p>';
  visual_editor_contents[ 2 ] = '<p>Beginner package content</p>';
  visual_editor_contents[ 3 ] = '<p>Business package content</p>';
  visual_editor_contents[ 4 ] = '<p>Advanced package content</p>';
  visual_editor_contents[ 5 ] = '<p>Additional services content</p>';
  visual_editor_contents[ 6 ] = '<p>New power server content</p>';
  visual_editor_contents[ 7 ] = '<p>Web hosting info content</p>';
  
  var visual_editor_titles = []
  visual_editor_titles[ 1 ] = '<b>Header text</b>';
  visual_editor_titles[ 2 ] = '<b>Beginner package</b>';
  visual_editor_titles[ 3 ] = '<b>Business package</b>';
  visual_editor_titles[ 4 ] = '<b>Advanced package</b>';
  visual_editor_titles[ 5 ] = '<b>Additional services</b>';
  visual_editor_titles[ 6 ] = '<b>New power server</b>';
  visual_editor_titles[ 7 ] = '<b>Web hosting info</b>';
  
  var current_visual_editor_number = 1;
  
  $(document).ready(
    
    function () {
      
      // set the height of the overlays ;)
      $('.overlay').css(
        'height',
        Math.max( $(document).height(), $(window).height(), document.documentElement.clientHeight )
      );
      
      // set the height of the supporting div, so none of the columns get cut off :)
      $('#columns_supporting_div').css( 'height', Math.max( $('#left_column' ).height(), $('#right_column' ).height() ) + 24 );
      
      /* the images slider */
      $("#home_page_slider").easySlider({
        auto: true, 
        continuous: true
      });
      
      /* the tag lines slider */
      $("#tag_lines_slider").easySlider({
        auto: true, 
        continuous: true,
        vertical: true,
        firstShow: true
      });
      
      $('#home_page_slider').css( 'height', '283px' );
      
      /* the pages submenus */
      $(".subpages").hover(
        function() {
          var top_page_id = parseInt( this.id.substring( 9 ) );
          // $(".subpages_" + top_page_id ).slideDown( 'fast' );
          $(".subpages_" + top_page_id ).show();
        },
        function() {
          var top_page_id = parseInt( this.id.substring( 9 ) );
          // $(".subpages_" + top_page_id ).slideUp( 'fast' );
          $(".subpages_" + top_page_id ).hide();
        }
      );
      
      // init the clock flash :)
      init_clock_flash();
      
      // the header banner flash embedding 
       $('#header_flash_itself_div').flash( {
        'src': siteUrl + 'img/banner.swf',
        'width' : '211px',
        'height' : '68px',
        'wmode' : 'transparent'
       } );
      
      // customizing the weather widget :)
      // $('.GENXVwxNewStyle table').first().css( 'background', 'url( ' + siteUrl + 'img/widget.bg.png ) repeat-x top left' );
      
      // and set the weather widgets links the "target" attribute to "_blank" :)
      $('.GENXVwxNewStyle a').attr( 'target', '_blank' );
      
      // and init the dragging functionality of the main column :)
      $('.main_column').Drags( {
        handler: '#main_content_glass_box_container'
      } );
      
      // and set the height of the columns supporting div :)
      $('#columns_supporting_div').css(
        'height',
        Math.max( $('#left_column' ).height(), $('#right_column' ).height(), $('#main_column' ).height() )
      );
      
    }
    
  );
  // window.onload = init;
  
  function showIF() {
    
    var instanceTwo = new ImageFlow();
    
    instanceTwo.init(
      {
        ImageFlowID : 'VideosThumbnails',
        reflectPath : siteUrl,
        reflectionPNG : false,
        reflectionGET : '', /* &p=' + siteUrl, */
        preloadImages : false,
        imagePath: '/images/movies/',
        circular: true,
        glideToStartID: false,
        slider: false,
        onClick: function() {
          showVideoPlayerInOverlay( this.getAttribute('longdesc') );
        }
      }
    );
    
  }
  
  function init_clock_flash() {
    // the left column flash embedding 
     $('#clock_flash').flash( {
      'src': siteUrl + 'img/clock.swf',
      'width' : '100px',
      'height' : '100px',
      'wmode' : 'transparent'
     } );
  }
  
  
  // the common ajax function :)
  function get_page( url, params, ajax_type ) {
    
    $('#overlay').show();
    
    var params = params;
    
    if( params === undefined ) {
      var params = {};
    }
    
    params.is_ajax_request = 1;
    
    params.is_home_page = isHomePage;
    if( ajax_type == 'ajax_from_nowhere' ) {
      params.is_ajax_request_from_nowhere = 1;
    } else {
      var hash = url;
      hash = hash.split( siteUrl );
      window.location.hash = '/' + hash[1];
    }
    
    $.post(
      url,
      params,
      function(data) {
        
        // parse the returned json :)
        data = $.parseJSON( data );
        
        // and check if we have to load the home page, or some internal page ... 
        if( 'page' in data && data.page == 'home' ) {
          
          $( '#internal_container' ).css( 'display', 'none' );
          $( '#left_column' ).html( '' );
          $( '#main_column' ).html( '' );
          $( '#right_column' ).html( '' );
          $( '#home_container' ).css( 'display', 'block' );
          
          isHomePage = true;
          
        } else if( ajax_type != 'ajax_from_nowhere' ) {
          
          $( '#home_container' ).css( 'display', 'none' ).html( '' );
          $( '#internal_container' ).css( 'display', 'block' );
          
          isHomePage = false;
          
        }
        
        // and if we have at least one content to populate in specific containers - we do it :)
        var we_have_loaded_a_main_content_data = false;
        var we_have_loaded_a_main_content_from_nowhere_data = false;
        var we_have_loaded_a_main_column_data = false;
        
        if( ( 'containers' in data ) && ( 'htmls' in data ) ) {
          
          for( var i = 0; i < data.htmls.length; i++ ) {
            
            if( data.containers[i] == 'main_content' ) {
              
              if( ajax_type == 'ajax_from_internal_page' ) {
                we_have_loaded_a_main_content_data = true;
              }
              if( ajax_type == 'ajax_from_nowhere' ) {
                we_have_loaded_a_main_content_from_nowhere_data = true;
              }
              
              new_content = '<div class="page_title">' + data.titles[i] + '</div><div id="content" class="content">' + data.htmls[i] + '</div>';
              $('#new_content_container').html( new_content );
              
            } else if( data.containers[i] == 'main_column' ) {
              
              we_have_loaded_a_main_column_data = true;
              
              new_content = data.htmls[i];
              $('#new_content_container').html( new_content );
              
            } else {
              
              $( '#' + data.containers[i] ).html( data.htmls[i] );
              
            }
            
            if( data.containers[i] == 'left_column' ) {
              init_clock_flash();
            }
            
          }
          
        }
        
        // and highlight the appropriate links in the menus :)
        if( 'top_page_id' in data ) {
          
          highlight_menus_link( topPageId, data.top_page_id );
          
          if( ajax_type != 'ajax_from_nowhere' ) {
            last_opened_top_page_id = topPageId;
          }
          
        }
        
        // and if we have to expand the main column content box - we do it ;)
        if( we_have_loaded_a_main_content_data || we_have_loaded_a_main_column_data ) {
          
          var new_content_height = $('#new_content_container').css( 'height' );
          $('#main_content').animate( { 'width' : 480, 'height' : new_content_height }, 200 );
          $('#main_content_glass_box_container').animate( { 'width' : 548 }, 200 );
          $('#before_main_column').animate( { 'height' : 1 }, 200 );
          
          if( we_have_loaded_a_main_column_data ) {
            
            t = setTimeout( '$("#main_column").html( new_content ); $("#new_content_container").html( "" ); if( $("#main_column").css("top") != "30px" || $("#main_column").css("left" ) != "110px" ) { $("#main_content_return_link").show(); } else { $("#main_content_return_link").hide(); }', 200 );
            
          } else {
            t = setTimeout( '$("#main_content").html( new_content ); $("#new_content_container").html( "" );', 200 );
          }
          
        }
        
        // and if we have to expand the content from nowhere box - we do it ;)
        if( we_have_loaded_a_main_content_from_nowhere_data ) {
          
          var new_content_height = $('#new_content_container').css( 'height' );
          
          $('#main_column_content_from_nowhere').animate( { 'width' : 480, 'height' : new_content_height }, 200 );
          $('#main_content_from_nowhere_glass_box_container').animate( { 'width' : 548 }, 200 );
          $('#before_main_column_from_nowhere').animate( { 'height' : 100 }, 200 );
          
          t = setTimeout( '$("#main_column_content_from_nowhere").css( { "overflow" : "visible" } ).html( new_content + "<a href=\'\' class=\'popin_close_link\' id=\'content_from_nowhere_close_link\'><img src=\'' + siteUrl + 'img/close.icon.png\' /></a>" ); $("#content_from_nowhere_close_link").click( function() { close_popin_from_nowhere(); return false; } ); $("#new_content_container").html( "" );', 200 );
          
          // and we scroll to the top of the page :)
          window.scroll( 0, 0 );
          
        }
        
        // the demo-form submition - if we're on the 7-th page :)
        if( 'page_id' in data && data.page_id == 7 ) {
          $( '#demo_submit' ).click( function() {
            var content = FCKeditorAPI.GetInstance('demo').GetXHTML();
            $( '#fckeditor_result' ).html( content );
            return false;
          } );
        }
        
        // and for the home page - we init the flash with the talking woman again :)
        if( 'page' in data && data.page == 'home' ) {
					var taking_woman_script_string = '<object data="http://content.oddcast.com/vhss/vhss_v5.swf?doc=http%3A%2F%2Fvhss-d.oddcast.com%2Fphp%2FplayScene%2Facc%3D197286%2Fss%3D1201125%2Fsl%3D0&amp;acc=197286&amp;bgcolor=0x&amp;pageDomain=localhost&amp;lc_name=1295156389&amp;fv=9&amp;is_ie=0&amp;emb=8&amp;embedid=9d1e9d3faf0642b75bef7b10c35a2b4c" id="VHSS" type="application/x-shockwave-flash" width="180" height="135"><param value="noborder" name="scale"><param value="" name="bgcolor"><param value="high" name="quality"><param value="VHSS" name="name"><param value="always" name="allowscriptaccess"><param value="true" name="swliveconnect"><param value="transparent" name="wmode"></object>';
          $( '#home_page_talkin_man' ).append( taking_woman_script_string );
        }
        
        // and we set the height of the supporting div - so left and right column don't cut when main content is small :)
        // alert( Math.max( $('#left_column' ).height(), $('#right_column' ).height() ) + ' : ' + $('#left_column' ).height() + ' : ' + $('#right_column' ).height() );
        
        // hide the overlay :)
        $('#overlay').hide();
        
        // the demo-form submition - if we're on the 14-th page :)
        if( 'page_id' in data && data.page_id == 14 ) {
          
          // and init the dragging functionality of the main column :)
          timeout_for_dragndrop = setTimeout(
            "init_drag_and_drop_and_supporting_div( true );",
            500
          );
          
        } else {
          
          // and init the dragging functionality of the main column :)
          timeout_for_dragndrop = setTimeout(
            "init_drag_and_drop_and_supporting_div();",
            500
          );
          
        }
        
      },
      function() {
        
      }
    );
    
  }
  
  function init_drag_and_drop_and_supporting_div( including_image_flow ) {
    
    clearTimeout( timeout_for_dragndrop );
    $('#columns_supporting_div').css(
      'height',
      Math.max( $('#left_column' ).height(), $('#right_column' ).height(), $('#main_column' ).height() )
    );
    $('.main_column').Drags( { handler: '#main_content_glass_box_container'} );
    
    if( including_image_flow != null ) {
      showIF();
    }
    
  }
  
  function return_main_content_area() {
    $("#main_column").animate( { 'left' : '110px', 'top' : '30px' }, 128 );
    $("#main_content_return_link").hide();
  }
  
  function get_ajax_page( url, params ) {
    
    // remove the FCK editor instance - if we have one :)
    removeFCKeditor( 'demo' );
    
    ajax_url = url;
    ajax_params = params;
    
    if( !isHomePage ) {
      
      $('#main_content').css( { 'background-image' : 'url( ' + siteUrl + 'img/semitransparent.white.png )', 'text-align' : 'center' } ).html( '<table style="width:100%; height:100%;" cellpadding="0" cellspacing="0"><tr><td align="center" valign="middle"><img src="' + siteUrl + 'img/loading.gif" /></td></tr></table>' );
      
      $('#main_content').animate( { 'width' : 32, 'height' : 32 }, 200 );
      $('#main_content_glass_box_container').animate( { 'width' : 100}, 200 );
      $('#before_main_column').animate( { 'height' : 100 }, 200 );
      
      var t = setTimeout( 'get_page( ajax_url, ajax_params, "ajax_from_internal_page" );', 200 );
      
    } else {
      
      get_page( ajax_url, ajax_params );
      
    }
    
  }
  
  
  function get_ajax_page_from_nothing( url, params ) {
    
    $('#content_from_nowhere_overlay').css( 'display', 'block' );
    $('#main_column_content_from_nowhere').css( { 'text-align' : 'center' } ).html( '<table style="width:100%; height:100%;" cellpadding="0" cellspacing="0"><tr><td align="center" valign="middle"><img src="' + siteUrl + 'img/loading.gif" /></td></tr></table>' );
    
    $('#before_main_column_from_nowhere').css( { 'height' : 390 } );
    
    get_page( url, params, 'ajax_from_nowhere' );
    
  }
  
  
  function close_popin_from_nowhere() {
    
    if( last_opened_top_page_id != false && last_opened_top_page_id != topPageId ) {
      highlight_menus_link( topPageId, last_opened_top_page_id );
    }
    
    $('#main_column_content_from_nowhere').html( '<table style="width:100%; height:100%;" cellpadding="0" cellspacing="0"><tr><td align="center" valign="middle"><img src="' + siteUrl + 'img/loading.gif" /></td></tr></table>' );
    
    $('#main_column_content_from_nowhere').animate( { 'width' : 32, 'height' : 32 }, 200 );
    $('#main_content_from_nowhere_glass_box_container').animate( { 'width' : 100 }, 200 );
    $('#before_main_column_from_nowhere').animate( { 'height' : 390 }, 200 );
    var t = setTimeout( '$("#content_from_nowhere_overlay").hide(); $("#main_column_content_from_nowhere").html( "<img src=\'' + siteUrl + 'img/loading.gif\' />" );', 200 );
    
  }
  
  
  function ajax_contact_form( action_url ) {
    
    // get the form values :)
    params = {
      'type' : $('#type').val(),
      'name_message' : $('#name_message').val(),
      'email' : $('#email').val(),
      'phone' : $('#phone').val(),
      'submit' : '1'
    }
    
    form_action_url = action_url;
    
    $('#main_column_content_from_nowhere').html( '<table style="width:100%; height:100%;" cellpadding="0" cellspacing="0"><tr><td align="center" valign="middle"><img src="' + siteUrl + 'img/loading.gif" /></td></tr></table>' );
    
    $('#main_column_content_from_nowhere').animate( { 'width' : 32, 'height' : 32 }, 200 );
    $('#main_content_from_nowhere_glass_box_container').animate( { 'width' : 100 }, 200 );
    $('#before_main_column_from_nowhere').animate( { 'height' : 390 }, 200 );
    
    var t = setTimeout( 'get_page( form_action_url, params, "ajax_from_nowhere" ); $("#main_column_content_from_nowhere").html( "<img src=\'' + siteUrl + 'img/loading.gif\' />" );', 200 );
    
  }
  
  function highlight_menus_link( old_top_page_id, new_top_page_id ) {
    
    // remove the "current" class from the links in the menus :)
    $('#horizontal_menu_link_'+old_top_page_id).removeClass( 'horizontal_menu_link_current' ).addClass( 'horizontal_menu_link' );
    $('#footer_link_'+old_top_page_id).removeClass( 'footer_link_current' ).addClass( 'footer_link' );
    
    // and add the "current" class to the specified link in the menus :)
    $('#horizontal_menu_link_'+new_top_page_id).removeClass( 'horizontal_menu_link' ).addClass( 'horizontal_menu_link_current' );
    $('#footer_link_'+new_top_page_id).removeClass( 'footer_link' ).addClass( 'footer_link_current' );
    
    topPageId = new_top_page_id;
    
  }
  
  // the function that removes the FCK editor instance ;)
  function removeFCKeditor( instanceName ) {
    
    if( typeof( FCKeditorAPI ) !== 'undefined' ) {
      var editorInstance = FCKeditorAPI.GetInstance( instanceName );
      var editorContainer = $('#' + instanceName + '___Frame');
      editorContainer.parent().remove();
    }
    
  }
  
  // the functions that show and hide the video player in overlay and plays the movie ;)
  function showVideoPlayerInOverlay( videoNumber ) {
    $('#videosOverlay').show().css( {
      'text-align' : 'center',
      'height' : '100%'
    } );
    $('#video_player_in_overlay').show().flash( {
      'src': siteUrl + 'img/player.swf',
      'width' : '400px',
      'height' : '248px',
      'wmode' : 'transparent',
      'allowfullscreen' : 'true',
      'flashvars' : { 'file' : siteUrl + 'images/movies/' + videoNumber + '.flv', 'allowFullscreen' : 'true', 'image' : siteUrl + 'images/movies/' + videoNumber + '.jpg' }
    } );
  }
  
  function hideVideoPlayerInOverlay() {
    $('#videosOverlay').hide();
    $('#video_player_div_in_overlay').html( '<div id="video_player_in_overlay"></div>' );
  }
  
  
  function visualEditorDemoContentsSetting() {
    var content_from_editor = FCKeditorAPI.GetInstance( 'demo' ).GetXHTML();
    visual_editor_contents[ current_visual_editor_number ] = content_from_editor;
    current_visual_editor_number = $('#visualEditorDropdown').val();
    FCKeditorAPI.GetInstance( 'demo' ).SetHTML( visual_editor_contents[ current_visual_editor_number ] );
  }
  
  var timeout_for_the_demo_contents;
  
  function visualEditorDemoProcess() {
    var number_of_selected_content = $('#visualEditorDropdown').val();
    var content_from_editor = FCKeditorAPI.GetInstance( 'demo' ).GetXHTML();
    visual_editor_contents[ number_of_selected_content ] = content_from_editor;
    
    /* show the overlay and the layout for the result of the demo */
    $('#cms_content_from_nowhere_overlay').css( 'display', 'block' );
      
      /* animate the table */
      $('#cms_main_content_from_nowhere_glass_box_container').animate( { 'width' : 740, 'height' : 868 }, 200 );
      /* animate the div before the table (the top offset of the table) */
      $('#cms_before_main_column_from_nowhere').animate( { 'height' : 120 }, 200 );
      
      /* and show the content after 200 ms */
      timeout_for_the_demo_contents = setTimeout( '$("#cms_main_column_content_from_nowhere").css( "display", "block" ); clearTimeout( timeout_for_the_demo_contents );', 200 );
    
    /* recalculate the height of the overlay divs */
    $('.overlay').css(
      'height',
      Math.max( $(document).height(), $(window).height(), document.documentElement.clientHeight )
    );
    
    /* and populate the entered data */
    for( var i = 1; i < 8; i++ ) {
      // visual_editor_contents[ i ] = splitTextForDemo( visual_editor_contents[ i ], i );
      $( '#fckeditor_result_'+i ).html( visual_editor_titles[ i ] + visual_editor_contents[ i ] );
    }
  }
  function visualEditorDemoClose() {
    
    $('.fckeditor_result').html('');
    
    /* animate the table */
    $('#cms_main_content_from_nowhere_glass_box_container').animate( { 'width' : 100, 'height' : 100 }, 200 );
    /* animate the div with the content inside the table */
    $('#cms_main_column_content_from_nowhere').css( 'display', 'none' );
    /* animate the div before the table (the top offset of the table) */
    $('#cms_before_main_column_from_nowhere').animate( { 'height' : 520 }, 200 );
    
    /* and show the content after 200 ms */
    timeout_for_the_demo_contents = setTimeout( '$("#cms_content_from_nowhere_overlay").css( "display", "none" );', 200 );
  }
  
  function splitTextForDemo( stringFromEditor, contentNumber ) {
    if( stringFromEditor != null && stringFromEditor != '' ) {
      if( contentNumber == 1 ) {
        var linesNumber = 4;
        var lineChars = 15;
      } else if( contentNumber == 2 ) {
        var linesNumber = 5;
        var lineChars = 25;
      } else {
        var linesNumber = 5;
        var lineChars = 10;
      }
      var linesArray = stringFromEditor.split('</p><p>');
      var newLinesArray = [];
      for( var i = 0; i < linesNumber; i++ ) {
        var lineText = linesArray[i];
        if( lineText != null && lineText != "" && lineText != "&nbsp;" ) {
          lineText = lineText.replace( "<p>", "" );
          lineText = lineText.replace( "</p>", "" );
          if( lineText.length > lineChars ) {
            lineText = lineText.substr( 0, lineChars );
          }
          newLinesArray[i] = lineText;
        }
      }
      var finalText = "<p>" + newLinesArray.join( '</p><p>' ) + "</p>";
      return finalText;
    } else {
      return '';
    }
  }
  
  
  

