$('HTML').addClass('JS');
var picno = 1, imageList = [], captionList = [], cycleStarted = false;

$(function() {
    $('a[rel$="external"]').live('click',function(){this.target = "_blank";});
    if ($(".accordion").length){
        $('.accordion').accordion({
            active: '.selected',
            header: "dt",
            autoheight: false
        })
    }
    $('.project-list').mouseover(function(){
        $(this).addClass('on');
    }).mouseout(function(){
        $(this).removeClass('on');
    });

    $('#pnav > li').mouseover(function(){
        $(this).addClass('hover');
    }).mouseout(function(){
        $(this).removeClass('hover');
    });

    $('#ddtab').toggle(function(){
        $('#dropdownbox').stop().animate({marginTop:'+=382px'},500);
    }, function(){
        $('#dropdownbox').stop().animate({marginTop:'-=382px'},300);
    });

    // add 30 by 90
    $(".wc1").colorbox({width:"798", height:"650", iframe:true});
    $(".wc2").colorbox({width:"810", height:"680", iframe:true});
    $(".vid1").colorbox({width:"798", height:"522", iframe:true});
    $(".imgpop").colorbox({maxWidth:"900", maxHeight:"530"});
    $(".pophs").colorbox({width:"800", height:"500", iframe:true});
	//sitefunctions.textresize();
    $("#main").pngFix();
});

function changeImage(newpic,nocap){
    var currentBG = $('#bg img').attr('src');
    $('#bg2 img').attr('src', currentBG);
    $('#bg2 img').show();
    var img = new Image();
    $(img).load(function () {
        $('#bg').empty();
        $('#bg').append(this);
        $(this).css({width:'100%',height:'auto'})
        $('#bg2 img').fadeOut(1000);
        if(nocap !=1){
            $('#sscaption').html(captionList[picno]+'&nbsp;&nbsp;');
            picno = picno + 1;
            if (picno > imageList.length - 1){picno = 0}
        }
    }).attr('src', newpic );
}

function cycleImages() {
        cycleStarted = true;
	if (imageList[picno] != undefined ){
            changeImage('/lib/'+imageList[picno]);
            setTimeout("cycleImages()", 5000);
	}else{
            cycleStarted = false;
        }
}
