/***
 * 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);
			cutline_obj.innerHTML = cutlines[current] + "<br /><b>" + media_author[current] + "</b> " + media_author2[current] + "";
			if (file_types[current] == "Audio")
				cutline_obj.innerHTML = cutline_obj.innerHTML+'<a href="' + pic_list[current] + '">Download Audio</a>';
			if (file_types[current] == "Video")
				cutline_obj.innerHTML = '<span style="color:#666666;">Double-click on video for fullscreen view.</span><br />' + cutline_obj.innerHTML;
		}
		
		// x of x text (current pic)
		if (c_pic_container) c_pic_container.innerHTML = (current+1) + ' of ' + pic_list.length + '&nbsp;<a href="javascript:;" onclick="media_viewer=window.open(\'\',\'name\',\'height=800,width=850,toolbar=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0\');popup_viewer(media_viewer);" style="text-decoration:underline;">View Larger</a>';
}

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") {
    	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;" onclick="gotoLink()" />';
    	// fade in image
    	for(i = 0; i < 100; i++) {
        	setTimeout("changeOpac(" + i + ",'big_pic')",(timer * speed));
        	timer++;
    	}
    }
    else {
    	if (file_types[current] == "Doc") {
    		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") {
    		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") {
    		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") {
    		// 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 popup_viewer(win) {
	//day = new Date();
	//id = day.getTime();
	//viewer = window.open(href, id, 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=550,height=450');
	if ((file_types[current] == "Audio") || (file_types[current] == "Flash")) {
		win.document.write('<html><head><title>Larger '+file_types[current]+'</title><style>*{margin:0;padding:0;}</style></head><body><center><embed src="'+pic_list[current]+'" autostart="true" loop="false" mute="true" style="background-color:#666666;"></embed><br /><a style="font:bold 10pt Verdana,Sans-Serif;" href="'+pic_list[current]+'">Download Audio</a><br /><br /><div style="text-align:left;font:normal 8pt Verdana,Sans-Serif;padding:5px;background-color:#f0f0f0;">'+cutlines[current]+'<br /><b>'+media_author[current]+' '+media_author2[current]+'<br /><br /></b><br /><br /><p style="width:100%;text-align:center;"><a href="javascript:window.close();" style="font-size:8pt;">Close Window</a></p></div></center></body></html>');
	}
	if (file_types[current] == "Video") {
		win.document.write('<html><head><title>Larger Video</title><style>*{margin:0;padding:0;}</style></head><body><center>' +
							'<object id="MediaPlayer" width="640" height="480" 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="DisplaySize" value="1" />' +
							'<param name="AllowChangeDisplaySize" value="true" />' +
							'<param name="ShowDisplay" value="1" />' +
							'<param name="fullScreen" value="false" />' +
							'<param name="stretchToFit" value="true" />' +
							'<param name="WindowlessVideo" value="1" />' +
						  	'<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="640" height="480" name="MediaPlayer" autostart="True" fullScreen="false" stretchToFit="true" ShowStatusBar="1" ShowControls="1" AllowDisplaySize="true" ShowDisplay="0"></embed>' +
						  	'</object>' +
							'<div style="font:normal 8pt Verdana,Sans-Serif;padding:5px;text-align:left;background-color:#f0f0f0;">'+cutlines[current]+'<br /><b>'+media_author[current]+'</b> '+media_author2[current]+'<br /><br /><p style="width:100%;text-align:center;"><a href="javascript:window.close();" style="font-size:8pt;">Close Window</a></p></div></center></body></html>');
	}
	if (file_types[current] == "Image") {
		win.document.write('<html><head><title>Larger Image</title><style>*{margin:0;padding:0;}</style></head><body><center><img src="'+pic_list[current]+'" width="800" /><br /><br /><div style="font:normal 8pt Verdana,Sans-Serif;padding:5px;text-align:left;background-color:#f0f0f0;">'+cutlines[current]+'<br /><b>'+media_author[current]+'</b> '+media_author2[current]+'<br /><br /><p style="width:100%;text-align:center;"><a href="javascript:window.close();" style="font-size:8pt;">Close Window</a></p></div></center></body></html>');
	}
	if (file_types[current] == "Doc") {
		win.document.write('<html><head><title>Download Document</title><style>*{margin:0;padding:0;}a{font:normal 10pt Verdana,Sans-Serif;}</style></head><body><center><br /><br /><br /><a href="'+pic_list[current]+'"><img src="'+doc_type_pic+'" width="50" border="0" /><br />Download Document</a><br /><br /><br /><div style="font:normal 8pt Verdana,Sans-Serif;padding:5px;text-align:left;background-color:#f0f0f0;">'+cutlines[current]+'<br /><b>'+media_author[current]+'</b> '+media_author2[current]+'<br /><br /><p style="width:100%;text-align:center;"><a href="javascript:window.close();" style="font-size:8pt;">Close Window</a></p></div></center></body></html>');
	}
}

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>';
}

function player_popup(href) {
	media_player = window.open(href,'2','toolbar=no,scrollbars=no,location=no,statusbar=no,menubar=no,resizable=no,width=760,height=420');
}
		