function $(id){return document.getElementById(id);}
function showClock(t){
	var months=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	var clock=new Date();
	var lmonth=months[clock.getMonth()];
	var date=clock.getDate();
	var year=clock.getYear();
	var hours=clock.getHours();
	var ampm=hours>12?" pm":" am";
	var minutes=clock.getMinutes();
	var seconds=clock.getSeconds();
	if(year<2000){year=year+1900;}
	if(hours<10){hours=" "+hours;}
	if(minutes<10){minutes="0"+minutes;}
	if(seconds<10){seconds="0"+seconds;}
	$(t).innerHTML=lmonth+" "+date+", "+year+" "+hours+":"+minutes+":"+seconds+" <span class='ampm'>"+ampm+"</span>";
	t=setTimeout('showClock("'+t+'")',500);
}
function story(){
    alert('New Addition Coming Soon\n\n  check back later, sorry :(');
}

/*
** GALLERY FUNCTIONS
**    maybe move these to gallery.js later
*/

// image fading
_over=new Array();
function fade(E,dir,duration){
    element=$(E);
    var opacity=Math.round(parseInt(element.style.MozOpacity)*100)/100;
    switch(dir){
        case 'in':  _over[E]=true;while(opacity<1){opacity+=.01;setTimeout('setOpacity("'+E+'",'+opacity+')',(duration*opacity));}break;
        case 'out': _over[E]=false;while(opacity>.3){opacity-=.01;fader=setTimeout('setOpacity("'+E+'",'+opacity+')',duration-(duration*opacity));}break;
    }
}
function setOpacity(E,level){$(E).setAttribute('style','-moz-opacity:'+level);if(level>=1){if(!_over[E]){fade(E,'out');}}}
function changeImage(i){
    if (_slideShow.length>=1){_slideShow.shift();}
    var L=$('large_image');
    var opacity=Math.round(parseInt(L.style.MozOpacity)*100)/100;
    while(opacity>.01){opacity-=.01;setTimeout("$('large_image').setAttribute('style','-moz-opacity:"+opacity+"');",500-(500*opacity));}
    $('loading').style.visibility='visible';
    L.onload=Function('$("loading").style.visibility="hidden";fade(this.id,"in",500);');
    L.onclick=Function('fullScreen(this.src)');
    L.src='/flickr/'+(i.replace(/__/gi,''));
}
// slider controls
_slide=false;
_speed=10;
_dir=0;
function slide(){
    var slidebar = $('cover');
    var max_distance = parseInt(slidebar.style.width)-644;
    if(_slide){
        var mov = _dir*_speed;
        var pos = parseInt(slidebar.style.left);
        var stop=false;
        if(_dir>0){if(pos>=0){stop=true;}}
        if(_dir<0){if(pos<=(-1*max_distance)){stop=true;}}
        if(!stop){slidebar.style.left=pos+(_dir*_speed)+"px";}
        setTimeout('slide()',100);
    }
}
function speedSlide(){_speed+=20;slide();_speed-=20;}

// slideshow
_slideShow=new Array();
function show(){
    $('showBtn').src='/img/stop.gif';
    $('showBtn').onclick=stopShow;
    var imx = $('cover').getElementsByTagName('img');
    for (var i=0;i<imx.length;i++) {
        _slideShow[i]=setTimeout("changeImage('"+imx[i].id+"');",i*6000);
    }
}
function stopShow(){
    for(i=0;i<_slideShow.length;i++){clearTimeout(_slideShow[i]);}
    _slideShow=new Array();
    $('showBtn').src='/img/slideshow.gif';
    $('showBtn').onclick=show;
}

// fullscreen
function fullScreen(img){
    html = "<html>"
          +"    <head>"
          +"    <script>"
          +"    function filler() {"
          +"        browseHeight=document.body.clientHeight;"
          +"        document.fred.height = browseHeight-100;"
          +"    }"
          +"    <\/script>"
          +"    </head>"
          +"    <body bgcolor='#000000' onload='filler()'>"
          +"    <table width=100% height=100%><tr>"
          +"    <td align=center>"
          +"    <img src="+img+" name='fred' height=600><br><br>"
          +"    <a href='javascript:window.close();'><font face='verdana' size='2' color='#FFFFFF'>Close</font></a>"
          +"    </table>"
          +"    </body>"
          +"    </html>"
          +"}"
    popup = window.open("","image","toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=0");
    popup.moveTo(0,0);
    popup.resizeTo(screen.width, screen.height);
    popup.document.open();
    popup.document.write(html);
    popup.focus();
    popup.document.close();
}
