var interval_id = 0;

function get_random_number ( max )
{
   var rand_no = Math.random();

   rand_no = rand_no * max;
   rand_no = Math.ceil(rand_no);

   return rand_no;
}

function htmlDecode(s)
{
    //return s.replace(/&(?!\w+([;\s]|$))/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
    return s.replace(/&lt;/g, "<").replace(/&gt;/g, ">");
}

function htmlEncode(s)
{
    return s.replace(/&(?!\w+([;\s]|$))/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
    //return s.replace(/&lt;/g, "<").replace(/&gt;/g, ">");
}

function hide_div (div_id)
{
    addiv = $(div_id)
    //addiv.hide()
    new Effect.Fade(addiv,{duration: 1, delay: 0});
}

function show_div (div_id)
{
    //alert(div_id)
    addiv = $(div_id)
    new Effect.Appear(addiv,{duration: 1.5, delay: 0});
}

function update_gallery ( img, img_href, div_id, img_text, img_width, img_height, clear_interval )
{

    //alert(img_href);

    if (clear_interval)
        clearInterval(interval_id);

    hide_div (div_id);

    img_text = img_text.replace(/\r\n/g, "");
    img_text = img_text.replace(/"/g, "\\\"");

    if (document.getElementById(div_id).innerHTML.indexOf('object') != -1)
        document.getElementById(div_id).innerHTML = "";

    var timeout_str = "set_background_teaser ( '"+img+"', '"+img_href+"', '"+div_id+"', \""+ img_text +"\", '"+img_width+"', '"+img_height+"')";

    //document.getElementById('debug').innerHTML += timeout_str +"\n";

    setTimeout(timeout_str, 1000);

    setTimeout( "show_div ( '"+ div_id +"')", 1000);
}

function set_background_teaser ( img, img_href, div_id, img_text, img_width, img_height, autostart )
{
    addiv = $(div_id)

    //addiv.style.display = 'none;'

    //addiv.hide()
    
    img_text = img_text.replace(/&amp;nbsp;/g, "&nbsp;");
    img_text = img_text.replace(/\&quot;/g, "\"");

    var imgs_array = new Array();
    imgs_array[0] = new Array(img, img_href);

    var set_width = 500;
    var text_right = false;
    var img_align = "center";

    if ( parseInt(img_width) < parseInt(img_height) )
    {
        set_width = 250;
        text_right = true;
        img_align = "align='left'";
        img_padding = "";
    }
    else if ( (img_height/img_width) >= .7 )
    {
        set_width = 350;
    }

    if (img_width == '' || img_height == '')
    {
        embed = '';
        if (img.indexOf('audio/playlist') != -1)
        {
            if (autostart)
                autostart = '&autoplay=true';
            else
                autostart = '';
                
            document.getElementById(div_id).style.background = "url(/media/images/Radio.jpg)";
            document.getElementById(div_id).style.width = "598px";
            document.getElementById(div_id).style.height = "450px";
            
            document.getElementById('album_pic').style.height = "450px";
            document.getElementById('album_pic').style.padding = "0px";
            document.getElementById('album_pic').style.width = "598px";
            
            document.getElementById('contentSolutions').style.height = "450px";
            document.getElementById('content').style.height = "480px";
            
           embed = '<div style="padding-top:430px; padding-left:180px;"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="400" height="15" id="xspf_player" align="middle">' +
                   '<param name="allowScriptAccess" value="sameDomain" />' +
                   '<param name="movie" value="/media/dash/xspf_player_slim.swf?playlist_url=' + img + autostart +'" />' +
                   '<param name="quality" value="high" />' +
                   '<param name="bgcolor" value="#e6e6e6" />' +
                   '<embed src="/media/dash/xspf_player_slim.swf?playlist_url=' + img + autostart +'" quality="high" bgcolor="#e6e6e6" width="400" height="15" name="xspf_player" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />' +
                   '</object></div>';
        }
        else if (img.indexOf('.flv') != -1)
        {
            if (autostart)
                autostart = 'true';
            else
                autostart = 'false';
        
            document.getElementById(div_id).style.background = "url(/media/images/TV.jpg)";
            document.getElementById(div_id).style.width = "598px";
            document.getElementById(div_id).style.height = "450px";
            
            document.getElementById('album_pic').style.height = "450px";
            document.getElementById('album_pic').style.padding = "0px";
            document.getElementById('album_pic').style.width = "598px";
            
            document.getElementById('contentSolutions').style.height = "450px";
            document.getElementById('content').style.height = "480px";
            
           embed = '<div style="padding-top:140px; margin-left:-105px;"><object width="320" height="240" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" >' +
                   '<param name="flashvars" value="file=' + img + '" />' +
                   '<param name="movie" value="/media/dash/flvplayer.swf?autostart='+autostart+'" />' +
                   '<param name="wmode" value="opaque" />' +
                   '<embed src="/media/dash/flvplayer.swf?autostart='+autostart+'" wmode="opaque" width="320" height="240" bgcolor="#FFFFFF" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="file=' + img + '" />' +
                   '</object></div>';
        }
      document.getElementById(div_id).innerHTML = embed;
    }
    else
    {
      var img_num = get_random_number ( imgs_array.length );

      document.getElementById(div_id).innerHTML =
             "<div><img id='teaser-image' style='text-align:center;' src='"+
                          imgs_array[img_num-1][0] +"' width='"+ set_width +"' "+
                          img_align +" />" +
                  "</div>";
    }

    //alert(text_right);
//     if (text_right == false)
//         document.getElementById(div_id).innerHTML += "<br>\n";

    if (img_text)
        document.getElementById(div_id).innerHTML += htmlDecode(img_text);


//    new Effect.Appear(addiv,{duration: 1.5, delay: 0});
//         setTimeout(function() {
//             new Effect.Parallel([
//                 new Effect.Appear(div_id, {sync: true})],
//                     //new Effect.Grow('teaser-image', {sync: true})],
//                     {duration: 1.5, delay: 0})
//         }, 0)

}
/*
Event.observe('teaser-image', 'load', function () {
	new Effect.Appear('teaser-image', {duration: 1.5})
})
*/
/***********************************************
* Ultimate Fade-In Slideshow (v1.51): � Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/
//var fadeimages=new Array()
//SET IMAGE PATHS. Extend or contract array as needed
//fadeimages[0]=["/media/slide_show/ss_1.jpg", "/about/", ""] //plain image syntax
//fadeimages[1]=["/media/slide_show/ss_2.jpg", "/about/", ""] //image with link syntax
//fadeimages[2]=["/media/slide_show/ss_3.jpg", "/about/", ""] //image with link and target syntax
//fadeimages[3]=["/media/slide_show/ss_4.jpg", "/about/", ""] //plain image syntax
//fadeimages[4]=["/media/slide_show/ss_5.jpg", "/about/", ""] //plain image syntax
//fadeimages[5]=["/media/slide_show/ss_6.jpg", "/about/", ""] //image with link syntax
//fadeimages[6]=["/media/slide_show/ss_7.jpg", "/about/", ""] //image with link syntax
//fadeimages[7]=["/media/images/img_main8.jpg", "/about/", ""] //plain image syntax
//fadeimages[8]=["/media/images/img_main9.jpg", "/about/", ""] //image with link syntax

var fadebgcolor="white"

////NO need to edit beyond here/////////////

var fadearray=new Array() //array to cache fadeshow instances
var fadeclear=new Array() //array to cache corresponding clearinterval pointers

var dom=(document.getElementById) //modern dom browsers
var iebrowser=document.all

function fadeshow(theimages, fadewidth, fadeheight, borderwidth, delay, pause, displayorder){
this.pausecheck=pause
this.mouseovercheck=0
this.delay=delay
this.degree=10 //initial opacity degree (10%)
this.curimageindex=0
this.nextimageindex=1
fadearray[fadearray.length]=this
this.slideshowid=fadearray.length-1
this.canvasbase="canvas"+this.slideshowid
this.curcanvas=this.canvasbase+"_0"
if (typeof displayorder!="undefined")
theimages.sort(function() {return 0.5 - Math.random();}) //thanks to Mike (aka Mwinter) :)
this.theimages=theimages
this.imageborder=parseInt(borderwidth)
this.postimages=new Array() //preload images
for (p=0;p<theimages.length;p++){
this.postimages[p]=new Image()
this.postimages[p].src=theimages[p][0]
}

var fadewidth=fadewidth+this.imageborder*2
var fadeheight=fadeheight+this.imageborder*2

if (iebrowser&&dom||dom) //if IE5+ or modern browsers (ie: Firefox)
document.write('<div id="master'+this.slideshowid+'" style="position:relative;width:'+fadewidth+'px;height:'+fadeheight+'px;overflow:hidden;"><div id="'+this.canvasbase+'_0" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);opacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1;background-color:'+fadebgcolor+'"></div><div id="'+this.canvasbase+'_1" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);opacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1;background-color:'+fadebgcolor+'"></div></div>')
else
document.write('<div><img name="defaultslide'+this.slideshowid+'" src="'+this.postimages[0].src+'"></div>')

if (iebrowser&&dom||dom) //if IE5+ or modern browsers such as Firefox
this.startit()
else{
this.curimageindex++
setInterval("fadearray["+this.slideshowid+"].rotateimage()", this.delay)
}
}

function fadepic(obj){
if (obj.degree<100){
obj.degree+=10
if (obj.tempobj.filters&&obj.tempobj.filters[0]){
if (typeof obj.tempobj.filters[0].opacity=="number") //if IE6+
obj.tempobj.filters[0].opacity=obj.degree
else //else if IE5.5-
obj.tempobj.style.filter="alpha(opacity="+obj.degree+")"
}
else if (obj.tempobj.style.MozOpacity)
obj.tempobj.style.MozOpacity=obj.degree/101
else if (obj.tempobj.style.KhtmlOpacity)
obj.tempobj.style.KhtmlOpacity=obj.degree/100
else if (obj.tempobj.style.opacity&&!obj.tempobj.filters)
obj.tempobj.style.opacity=obj.degree/101
}
else{
clearInterval(fadeclear[obj.slideshowid])
obj.nextcanvas=(obj.curcanvas==obj.canvasbase+"_0")? obj.canvasbase+"_0" : obj.canvasbase+"_1"
obj.tempobj=iebrowser? iebrowser[obj.nextcanvas] : document.getElementById(obj.nextcanvas)
obj.populateslide(obj.tempobj, obj.nextimageindex)
obj.nextimageindex=(obj.nextimageindex<obj.postimages.length-1)? obj.nextimageindex+1 : 0
setTimeout("fadearray["+obj.slideshowid+"].rotateimage()", obj.delay)
}
}

fadeshow.prototype.populateslide=function(picobj, picindex){
var slideHTML=""

// Make sure that the no image never shows.
while (this.theimages[picindex][0].indexOf('no-image') >= 0 )
    picindex++;

if (this.theimages[picindex][1]!="") //if associated link exists for image
{
//alert(this.theimages[picindex][0] +" "+ this.theimages[picindex][0].indexOf('no-image'))
//slideHTML='<a href="'+ this.theimages[picindex][0] +'">'+ this.theimages[picindex][0] +'</a>';
slideHTML='<a href="'+this.theimages[picindex][1]+'/" target="'+this.theimages[picindex][2]+'">';
slideHTML+='<img STYLE="width:265px" src="'+this.postimages[picindex].src+'" border="'+this.imageborder+'px">';
slideHTML+='</a>';
}



picobj.innerHTML=slideHTML
}


fadeshow.prototype.rotateimage=function(){
if (this.pausecheck==1) //if pause onMouseover enabled, cache object
var cacheobj=this
if (this.mouseovercheck==1)
setTimeout(function(){cacheobj.rotateimage()}, 100)
else if (iebrowser&&dom||dom){
this.resetit()
var crossobj=this.tempobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
crossobj.style.zIndex++
fadeclear[this.slideshowid]=setInterval("fadepic(fadearray["+this.slideshowid+"])",60)
this.curcanvas=(this.curcanvas==this.canvasbase+"_0")? this.canvasbase+"_1" : this.canvasbase+"_0"
}
else{
var ns4imgobj=document.images['defaultslide'+this.slideshowid]
ns4imgobj.src=this.postimages[this.curimageindex].src
}
this.curimageindex=(this.curimageindex<this.postimages.length-1)? this.curimageindex+1 : 0
}

fadeshow.prototype.resetit=function(){
this.degree=10
var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
if (crossobj.filters&&crossobj.filters[0]){
if (typeof crossobj.filters[0].opacity=="number") //if IE6+
crossobj.filters(0).opacity=this.degree
else //else if IE5.5-
crossobj.style.filter="alpha(opacity="+this.degree+")"
}
else if (crossobj.style.MozOpacity)
crossobj.style.MozOpacity=this.degree/101
else if (crossobj.style.KhtmlOpacity)
crossobj.style.KhtmlOpacity=this.degree/100
else if (crossobj.style.opacity&&!crossobj.filters)
crossobj.style.opacity=this.degree/101
}


fadeshow.prototype.startit=function(){
var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
this.populateslide(crossobj, this.curimageindex)
if (this.pausecheck==1){ //IF SLIDESHOW SHOULD PAUSE ONMOUSEOVER
var cacheobj=this
var crossobjcontainer=iebrowser? iebrowser["master"+this.slideshowid] : document.getElementById("master"+this.slideshowid)
crossobjcontainer.onmouseover=function(){cacheobj.mouseovercheck=1}
crossobjcontainer.onmouseout=function(){cacheobj.mouseovercheck=0}
}
this.rotateimage()
}
