cntr = 1;
var timeout = 8000;
var vid_pg = 0;
var reviews_pg = 0;
var trailers_pg = 0;
var wp_pg = 0;
var images_pg = 0;
var headlines_pg = 0;
var tf_pg = 0;
var myjoblo_pg = 0;

function cycle_top() { 
  cntr++;
  if (cntr == 6) { cntr = 1; }
  tmp = '/display-box.php?box_id=1&top_chosen=' + cntr;

  $.ajax({
    url: tmp,
    cache: false,
    success: function(html){
      $("#top_feature_box")
	.hide()
	.html(html);
      $("#featured_img").hide();
      $("#below_img").hide();
      $("#top_feature_box").show();
      $("#featured_img").fadeIn('slow');
      $("#below_img").show('slow');
    }
  });
}


function getCookie(c_name) {
  if (document.cookie.length>0) {
    c_start=document.cookie.indexOf(c_name + "=");
    if (c_start!=-1) { 
      c_start=c_start + c_name.length+1; 
      c_end=document.cookie.indexOf(";",c_start);
      if (c_end==-1) c_end=document.cookie.length;
      return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
  return "";
}




// jquery
$(document).ready(function(){

  // check and update any boxes that have locks
  var release_tab = getCookie('jb_release_dates_tab');
  if (release_tab != '') { 
    tmp = '/display-box.php?box_id=release_dates&release_category=' + release_tab;
    ajax_get(tmp,'release_dates');
    $("a.lock_release_dates_rollover").addClass('releases_locked');
  }
  var headlines_tab = getCookie('jb_headlines_tab');
  if (headlines_tab != '') { 
    tmp = '/display-box.php?box_id=headlines&release_section=' + headlines_tab;
    ajax_get(tmp,'latest_headlines');
    $("a.lock_mid_rollover").addClass('headlines_locked');
  }
  var videos_tab = getCookie('jb_videos_tab');
  if (videos_tab != '') { 
    tmp = '/display-box.php?box_id=4&featured_vid=' + videos_tab;
    ajax_get(tmp,'latest_joblo_videos');
    $("a.lock_right_27_rollover").addClass('videos_locked');
  }
  var reviews_tab = getCookie('jb_reviews_tab');
  if (reviews_tab != '') { 
    tmp = '/display-box.php?box_id=latest_reviews&review_section=' + reviews_tab;
    ajax_get(tmp,'latest_reviews');
    $("a.lock_right_28_rollover").addClass('reviews_locked');
  }
 


  // change lock icon when clicked.
  $("a.lock_mid_rollover").click(function(){ 
    $(this).addClass("headlines_locked");
  });
  $("a.lock_right_27_rollover").click(function(){
    $(this).addClass("videos_locked");
  });
  $("a.lock_right_28_rollover").click(function(){
    $(this).addClass("reviews_locked");
  });

});

var top_timer = setInterval('cycle_top()', timeout);

function set_cookie( name, value, expires, path, domain, secure ) {

  // set time, it's in milliseconds
  var today = new Date();
  today.setTime( today.getTime() );

  if ( expires ) {
    expires = expires * 1000 * 60 * 60 * 24;
  }

  // if cookie is currently set, unset it with negative expires date
  // and unlock the icon
  var current_cookie = getCookie(name);
  if (current_cookie != '') { 
    expires = expires * -1;
    switch(name) {
      case 'jb_release_dates_tab':
	$("a.lock_release_dates_rollover").removeClass('releases_locked');
	break;
      case 'jb_headlines_tab':
	$("a.lock_mid_rollover").removeClass('headlines_locked');
	break;
      case 'jb_videos_tab':
	$("a.lock_right_27_rollover").removeClass('videos_locked');
	break;
      case 'jb_reviews_tab':
	$("a.lock_right_28_rollover").removeClass('reviews_locked');
	break;
    }
  }


  var expires_date = new Date( today.getTime() + (expires) );
  document.cookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
    ( ( path ) ? ";path=" + path : "" ) +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );

  if (expires > 0) { 
    // switch the 'locked' icon
    if (name == 'jb_release_dates_tab') { 
      $("a.lock_release_dates_rollover").addClass('releases_locked');
    }
    else if (name == 'jb_headlines_tab') { 
      $("a.lock_mid_rollover").addClass('headlines_locked');
    }
    else if (name == 'jb_videos_tab') { 
      $("a.lock_right_27_rollover").addClass('videos_locked');
    }
    else if (name == 'jb_reviews_tab') { 
      $("a.lock_right_28_rollover").addClass('reviews_locked');
    }
  }
}


function page_video(dir) {
  var ml = 0;
  var mv_interval = 302;
  if (dir == 'next') { 
    vid_pg++;
    ml = vid_pg * mv_interval * -1;
    $("div#latest_joblo_videos_img_table table").animate({marginLeft: ml}, 700);
    $("a#vid_prev").show();
    if (vid_pg == 5) { 
      $("a#vid_next").hide();
    }
  }
  else { 
    vid_pg--;
    ml = vid_pg * mv_interval * -1;
    $("div#latest_joblo_videos_img_table table").animate({marginLeft: ml}, 700);
    $("a#vid_next").show();
    if (vid_pg == 0) { 
      $("a#vid_prev").hide();
    }
  }
}

function page_reviews(dir) {
  var ml = 0;
  var mv_interval = 312;
  if (dir == 'next') { 
    reviews_pg++;
    ml = reviews_pg * mv_interval * -1;
    $("div#latest_reviews_items div").animate({marginLeft: ml}, 700);
    $("a#reviews_prev").show();
    if (reviews_pg == 2) { 
      $("a#reviews_next").hide();
    }
  }
  else { 
    reviews_pg--;
    ml = reviews_pg * mv_interval * -1;
    $("div#latest_reviews_items div").animate({marginLeft: ml}, 700);
    $("a#reviews_next").show();
    if (reviews_pg == 0) { 
      $("a#reviews_prev").hide();
    }
  }
}

function page_trailers(dir) {
  var ml = 0;
  var mv_interval = 300;
  if (dir == 'next') { 
    trailers_pg++;
    ml = trailers_pg * mv_interval * -1;
    $("div#latest_trailers_img_table table").animate({marginLeft: ml}, 700);
    $("a#trailers_prev").show();
    if (trailers_pg == 5) { 
      $("a#trailers_next").hide();
    }
  }
  else { 
    trailers_pg--;
    ml = trailers_pg * mv_interval * -1;
    $("div#latest_trailers_img_table table").animate({marginLeft: ml}, 700);
    $("a#trailers_next").show();
    if (trailers_pg == 0) { 
      $("a#trailers_prev").hide();
    }
  }
}

function page_wallpapers(dir) {
  var ml = 0;
  var mv_interval = 400;
  if (dir == 'next') { 
    wp_pg++;
    ml = wp_pg * mv_interval * -1;
    $("div#latest_wallpaper_imgs table").animate({marginLeft: ml}, 700);
    $("a#wp_prev").show();
    if (wp_pg == 4) { 
      $("a#wp_next").hide();
    }
  }
  else { 
    wp_pg--;
    ml = wp_pg * mv_interval * -1;
    $("div#latest_wallpaper_imgs table").animate({marginLeft: ml}, 700);
    $("a#wp_next").show();
    if (wp_pg == 0) { 
      $("a#wp_prev").hide();
    }
  }
}


function page_images(dir) {
  var ml = 0;
  var mv_interval = 408;
  if (dir == 'next') { 
    images_pg++;
    ml = images_pg * mv_interval * -1;
    $("div#latest_images_imgs table").animate({marginLeft: ml}, 700);
    $("a#imgs_prev").show();
    if (images_pg == 4) { 
      $("a#imgs_next").hide();
    }
  }
  else { 
    images_pg--;
    ml = images_pg * mv_interval * -1;
    $("div#latest_images_imgs table").animate({marginLeft: ml}, 700);
    $("a#imgs_next").show();
    if (images_pg == 0) { 
      $("a#imgs_prev").hide();
    }
  }
}


function page_headlines(dir) {
  var mt = 0;
  var mv_interval = 595;
  if (dir == 'next') { 
    headlines_pg++;
    mt = headlines_pg * mv_interval * -1;
    $("table#latest_headlines_table").animate({marginTop: mt}, 1000);
    $("a#headlines_prev").show();
    if (headlines_pg == 4) { 
      $("a#headlines_next").hide();
    }
  }
  else { 
    headlines_pg--;
    mt = headlines_pg * mv_interval * -1;
    $("table#latest_headlines_table").animate({marginTop: mt}, 1000);
    $("a#headlines_next").show();
    if (headlines_pg == 0) { 
      $("a#headlines_prev").hide();
    }
  }
}

function page_tf(dir) {
  var mt = 0;
  var mv_interval = 700;
  if (dir == 'next') { 
    tf_pg++;
    mt = tf_pg * mv_interval * -1;
    $("table#top_features_table").animate({marginTop: mt}, 1000);
    $("a#tf_prev").show();
    if (tf_pg == 4) { 
      $("a#tf_next").hide();
    }
  }
  else { 
    tf_pg--;
    mt = tf_pg * mv_interval * -1;
    $("table#top_features_table").animate({marginTop: mt}, 1000);
    $("a#tf_next").show();
    if (tf_pg == 0) { 
      $("a#tf_prev").hide();
    }
  }
}

function page_myjoblo(dir) {
  var mt = 0;
  var mv_interval = 100;
  if (dir == 'next') { 
    myjoblo_pg++;
    mt = myjoblo_pg * mv_interval * -1;
    $("table#myjoblo_table").animate({marginTop: mt}, 1000);
    $("a#myjoblo_prev").show();
    if (myjoblo_pg == 4) { 
      $("a#myjoblo_next").hide();
    }
  }
  else { 
    myjoblo_pg--;
    mt = myjoblo_pg * mv_interval * -1;
    $("table#myjoblo_table").animate({marginTop: mt}, 1000);
    $("a#myjoblo_next").show();
    if (myjoblo_pg == 0) { 
      $("a#myjoblo_prev").hide();
    }
  }
}

