// JavaScript Document

var imgs = new Array();
imgs[0] = "images/home/img1.jpg";
imgs[1] = "images/home/img2.jpg";
imgs[2] = "images/home/img3.jpg";
imgs[3] = "images/home/img4.jpg";

var imgLinks = new Array();
imgLinks[0] = "/viewer/graduate_portfolio.aspx?a=p&p=1346";
imgLinks[1] = "/viewer/graduate_portfolio.aspx?p=852"; 
imgLinks[2] = "/p/charlottesummers"; 
imgLinks[3] = "/video.html"; 

var effects = new Array(); 
effects[1] = "explode";
effects[2] = "fold";
effects[3] = "puff";
effects[4] = "drop";

var cur_id = 0;
var timer = 0;


$(document).ready(function(){
	jQuery.preLoadImages(imgs[0], imgs[1], imgs[2], imgs[3]);
	$(".showVideo a").colorbox();
	animateImgs();
   $('.promo_img').mouseover(clearAnimation);
   $('.promo_img').mouseleave(restartAnimateImgs);
   $('#jsddm > li').bind('mouseover', jsddm_open);
   $('#jsddm > li').bind('mouseout', jsddm_timer);})

document.onclick = jsddm_close;

function showImg(){
    var id = $(this).attr('rel');
    
    if (id == 4)
        $('.promo_img').html("<span class='showVideo'><a href='" + imgLinks[(id)] + "'><img src='" + imgs[(id)] + "' /></a></span>");
	else 
	    $('.promo_img').html("<a href='"+imgLinks[(id)]+"'><img src='"+imgs[(id)]+"' /></a>");
}

function animateImgs(){
  if (cur_id > 3)
  	cur_id = 0;

    if (cur_id == 3) {        $('.promo_img').html("<span class='showVideo'><a href='" + imgLinks[(cur_id)] + "'><img src='" + imgs[(cur_id)] + "' border='0' /></a></span>");
        $(".showVideo a").colorbox();
    }
    else {
        $('.promo_img').html("<a href='" + imgLinks[(cur_id)] + "'><img src='" + imgs[(cur_id)] + "' border='0' /></a>");
    }
      
  $('.promo_img').fadeIn('slow');
  cur_id ++;
  timer = setTimeout( "animateOut()", 4000 );
}

function animateOut() {
	//$('.promo_img').effect(effects[cur_id], '', '', animateImgs); 
	$('.promo_img').effect('explode', '', '', animateImgs);     
}

function clearAnimation() {
	clearTimeout(timer);	
}

function restartAnimateImgs() {
	cur_id -= 1;
	animateImgs();
}


function googleTranslateElementInit() {
  new google.translate.TranslateElement({
    pageLanguage: 'en'
  }, 'google_translate_element');
}


(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)


var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open() {
    jsddm_canceltimer();
    jsddm_close();
    ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');
}

function jsddm_close()
{ if (ddmenuitem) ddmenuitem.css('visibility', 'hidden'); }

function jsddm_timer()
{ closetimer = window.setTimeout(jsddm_close, timeout); }

function jsddm_canceltimer() {
    if (closetimer) {
        window.clearTimeout(closetimer);
        closetimer = null;
    }
}
