/***
 * pic_list.js
 * Contents: contains functions that handle the ad
 *			 detail picture list navigation.
 * Matthew T. Carter
 **/

var in_ss = false;
var current = 0;
var global_timeout;

function updatePicList(iPic) {
		current = iPic;
		cutline_obj = document.getElementById("cutline_actual");
		c_pic_container = document.getElementById("pic_list_current");
		
		if (cutline_obj) {
			blendimage('big_pic_container',500);
			
			if (file_types[current] == "Audio")
				cutline_obj.innerHTML = '<a href="' + pic_list[current] + '">Download Audio</a><br />' + cutlines[current];
			else if (file_types[current] == "Video")
				cutline_obj.innerHTML = '(Video will play automatically when loaded.)<br />' + cutlines[current];
			else
				cutline_obj.innerHTML = cutlines[current];
		}
		
		// x of x text (current pic)
		if (c_pic_container) c_pic_container.innerHTML = (current+1) + ' of ' + pic_list.length;
}

function next() {
	updatePicListNav(false);
	in_ss = false;
	clearTimeout(global_timeout);
	if (current < (pic_list.length-1)) {
		current += 1;
		updatePicList(current);
	}
	else {
		current = 0;
		updatePicList(current);
	}
}

function prev() {
	updatePicListNav(false);
	in_ss = false;
	clearTimeout(global_timeout);
	if (current > 0) {
		current -= 1;
		updatePicList(current);
	}
	else {
		current = (pic_list.length-1);
		updatePicList(current);
	}
}

function toggle_ss() {
	in_ss = !in_ss;
}

function rotate() {
	if (in_ss == true) {
		current = (current == (pic_list.length-1)) ? 0 : current + 1;
		updatePicList(current);
		global_timeout = setTimeout("rotate()",global_timeout_time);
	}
}



updatePicList(0);

// fade functions
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

function blendimage(imageid, millisec) {
    var speed = Math.round(millisec / 100);
    var timer = 0;

    if ((file_types[current] == "Image") || (file_types[current].charAt(0) == "I")) {
    	document.getElementById(imageid).innerHTML = '<img id="big_pic" src="'+pic_list[current]+'" style="filter:alpha(opacity=0);opacity:0;-moz-opacity:0;display:block;position:relative;z-index:1;" />';
    	// fade in image
    	for(i = 0; i < 100; i++) {
        	setTimeout("changeOpac(" + i + ",'big_pic')",(timer * speed));
        	timer++;
    	}
    }
    else {
    	if ((file_types[current] == "Doc") || (file_types[current].charAt(0) == "D")) {
    		document.getElementById(imageid).innerHTML = '<center><br /><br /><br /><br /><br /><a href="'+pic_list[current]+'" target="_blank" style="margin-bottom:20px;"><img src="'+doc_type_pic+'" border="0" style="float:none;width:50px;height:50px;text-decoration:none;" /><br />(Click to download document.)</a></center><br /><br /><br /><br /><br /><br /><br />';
    	}
    	if ((file_types[current] == "Video")|| (file_types[current].charAt(0) == "V")) {
    		document.getElementById(imageid).innerHTML = '<img src="'+vid_launch_pic+'" width="338" height="254" onclick="launchVideo(\''+pic_list[current]+'\');" style="cursor:pointer;" />';
    		// document.getElementById(imageid).innerHTML = '<object type="video/x-ms-wmv" data="'+pic_list[current]+'" width="338" height="254"><param name="src" value="'+pic_list[current]+'" /><param name="autostart" value="false" /><param name="controller" value="true" /></object>';
    	}
    	if ((file_types[current] == "Audio") || (file_types[current].charAt(0) == "A")) {
    		document.getElementById(imageid).innerHTML = '<img src="'+audio_launch_pic+'" width="338" height="254" onclick="launchAudio(\''+pic_list[current]+'\');" style="cursor:pointer;" />';
    	}
    	if ((file_types[current] == "Flash") || (file_types[current].charAt(0) == "F")) {
    		// flash
    		document.getElementById(imageid).innerHTML = '<embed src="'+pic_list[current]+'" autostart="false" loop="false" mute="false" style="background-color:#666666;" width="338" height="254"></embed>';
    	}
    }
}

function launchVideo(s) {
	var container = document.getElementById("big_pic_container");
	// OLD METHOD: container.innerHTML = '<object type="video/x-ms-wmv" data="'+pic_list[current]+'" width="338" height="254"><param name="src" value="'+pic_list[current]+'" /><param name="autostart" value="true" /><param name="controller" value="true" /><param name="showstatusbar" value="true" /></object>';
	container.innerHTML = '<object id="MediaPlayer" width="338" height="254" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" standby="Loading Video" type="application/x-oleobject">' +
						  '<param name="URL" value="'+pic_list[current]+'" />' +
						  '<param name="AutoStart" value="True" />' +
						  '<param name="ShowControls" value="True" />' +
						  '<param name="ShowStatusBar" value="True" />' +
						  '<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/windows/mediaplayer/en/download/" src="'+pic_list[current]+'" width="338" height="254" name="MediaPlayer" autostart="True" ShowStatusBar="1" ShowControls="1" ></embed>' +
						  '</object>';
}

function launchAudio(s) {
	var container = document.getElementById("big_pic_container");
	container.innerHTML = '<embed src="'+pic_list[current]+'" autostart="true" loop="false" mute="false" style="background-color:#666666;" width="338" height="254"></embed>';
}