// JavaScript Document

// start FLASH CODE



// Hook for Internet Explorer.
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<script language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub BTN_home_FSCommand(ByVal command, ByVal args)\n');
	document.write('	Call BTN_home_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</script\>\n');
}

if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<script language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub BTN_projects_FSCommand(ByVal command, ByVal args)\n');
	document.write('	Call BTN_projects_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</script\>\n');
}

if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<script language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub BTN_about_FSCommand(ByVal command, ByVal args)\n');
	document.write('	Call BTN_about_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</script\>\n');
}

if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<script language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub BTN_archive_FSCommand(ByVal command, ByVal args)\n');
	document.write('	Call BTN_archive_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</script\>\n');
}
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<script language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub BTN_contact_FSCommand(ByVal command, ByVal args)\n');
	document.write('	Call BTN_contact_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</script\>\n');
}





var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;


// Handle all the FSCommand messages in a Flash movie.
function BTN_home_DoFSCommand(command, args) {
	var BTNObj = isInternetExplorer ? document.all.BTN : document.BTN;
	if (command == "getContent")
  {
    getContent(args);
  }
}
// Handle all the FSCommand messages in a Flash movie.
function BTN_projects_DoFSCommand(command, args) {
	var BTNObj = isInternetExplorer ? document.all.BTN : document.BTN;
	if (command == "getContent")
  {
    getContent(args);
  }
}
// Handle all the FSCommand messages in a Flash movie.
function BTN_archive_DoFSCommand(command, args) {
	var BTNObj = isInternetExplorer ? document.all.BTN : document.BTN;
	if (command == "getContent")
  {
    getContent(args);
  }
}
// Handle all the FSCommand messages in a Flash movie.
function BTN_about_DoFSCommand(command, args) {
	var BTNObj = isInternetExplorer ? document.all.BTN : document.BTN;
	if (command == "getContent")
  {
    getContent(args);
  }
}
// Handle all the FSCommand messages in a Flash movie.
function BTN_contact_DoFSCommand(command, args) {
	var BTNObj = isInternetExplorer ? document.all.BTN : document.BTN;
	if (command == "getContent")
  {
    getContent(args);
  }
}
// END FLASH CODE







function getContent(section)
{
	pause = true;
	$('ajax_div').innerHTML = "Please wait...";
	new Ajax.Request(section+'.html',
	  {
	    method:'get',
	    onSuccess: function(transport)
		{
			var response = transport.responseText || "no response text";
			switch (section)
			{
				case "Home":
				{
					pause = false;
					$('header_text').innerHTML = section;
					$('ajax_div').innerHTML = "";
					addElement('div','ajax_div', 'imageContainer', 'imageContainer');
	//				$('imageContainer').innerHTML = response;
					so_init();
					break;
				}
				case "Projects":
				{
					$('header_text').innerHTML = section;
					$('ajax_div').innerHTML = "";
				//	addElement('div','ajax_div', 'mycarousel', 'carousel-component');
				//	$('mycarousel').innerHTML = response;
					addCarouselToDoc(response);
					pageLoad();
					break;
				}
				case "project_template":
				{
					$('ajax_div').innerHTML = response;
					break;
				}
				default:
				{
					$('ajax_div').innerHTML = response;
					$('header_text').innerHTML = section;
				}
			}
	   },
	    onFailure: function(){ alert('Something went wrong...') }
	  });
	/*if (pngfix_var == 1)
		pngfix_func();*/
}

var current_project = '';

function getContent_project(_project_name, req_type,credits,cast)
{
	var toggle=false;
	if (_project_name == 'current'){
		_project_name = current_project;
		$('header_text').innerHTML = 'Projects >> ' + _project_name + ' >> ' + req_type;
	}
	else
	{
		toggle=true;
		current_project = _project_name;
		getContent('project_template');
		if (cast=='true'|credits=='true')	
			$('project_footer_div').innerHTML +='&nbsp;&nbsp;&nbsp;<a href="javascript:getContent_project(\'current\', \'synopsis\','+credits+','+cast+');">synopsis</a>';
		if (cast=='true')	
			$('project_footer_div').innerHTML +='&nbsp;&nbsp;&nbsp;<a href="javascript:getContent_project(\'current\', \'cast\','+credits+','+cast+');" >cast</a>';
		if (credits=='true')	
			$('project_footer_div').innerHTML +='&nbsp;&nbsp;&nbsp;<a href="javascript:getContent_project(\'current\', \'credits\','+credits+','+cast+');">credits</a>';
		
		$('header_text').innerHTML = $('header_text').innerHTML + ' >> ' + _project_name;
	}
	
	var text_file = 'DOC/' + _project_name + '_'  + req_type + '.txt';
	new Ajax.Request(text_file,
	{
	    method:'get',
	    onSuccess: function(transport)
		{
			
			var response = transport.responseText || "no response text";
			if (toggle){
				$('project_title').innerHTML =  _project_name;
				$('project_image').src = "img/projects/" + _project_name + ".jpg";
			}
			$('project_text').innerHTML = response;
						
		},
	    onFailure: function(){ alert('Something went wrong...') }
	 });
	
}
	
	
	var handleNextButtonState = function(type, args) {
	
		var enabling = args[0];
		var rightImage = args[1];
		
		if(enabling) {
			var _elem = document.getElementById(rightImage.id);
			_elem.style.visibility = "visible";
		} else {
			var _elem = document.getElementById(rightImage.id);
			_elem.style.visibility = "hidden";
		}
		
	};

function addCarouselToDoc(response)
{
	addElement('div','ajax_div', 'mycarousel', 'carousel-component');
	addElement('div','mycarousel', 'mycarousel-clip-region', 'carousel-clip-region');
	$('mycarousel-clip-region').innerHTML = response;
	addElement('div','mycarousel', 'btn_container', 'btn_con_projects');
	addElement('div','btn_container', 'next-arrow', 'right-button-image');
	addElement('div','btn_container', 'prev-arrow', 'left-button-image');
}


function addElement(elem_type, father_name, elem_id, _className)
{
  var ni = document.getElementById(father_name);
  var newElem = document.createElement(elem_type);
  newElem.setAttribute('id',elem_id);
  newElem.setAttribute('className',_className);
  ni.appendChild(newElem);
}


var handlePrevButtonState = function(type, args) {

	var enabling = args[0];
	var leftImage = args[1];
	if(enabling) {
		var _elem = document.getElementById(leftImage.id);
		_elem.style.visibility = "visible";
		} else {
		var _elem = document.getElementById(leftImage.id);
		_elem.style.visibility = "hidden";
	}
};


function pageLoad() 
{
	var carousel = new YAHOO.extension.Carousel("mycarousel", 
		{
			numVisible:        4,
			animationSpeed:   .25,
			scrollInc:         1,
			navMargin:         40,
			prevElement:     "prev-arrow",
			nextElement:     "next-arrow",
			size:              16,
		//	autoplay:			4000,
		//	wrap:				true,
			prevButtonStateHandler:   handlePrevButtonState,
			nextButtonStateHandler:   handleNextButtonState
		}
	);
};
	
	//YAHOO.util.Event.addListener("projects" , "click" , pageLoad);

   		
	
//YAHOO.util.Event.addListener("window" , "load", pageLoad);
/*
function my_init()
{
	var carousel = new YAHOO.extension.Carousel("mycarousel", 
	{
			numVisible:        1,
			animationSpeed:   .25,
			scrollInc:         1,
			navMargin:         40,
			prevElement:     "prev-arrow",
			nextElement:     "next-arrow",
			size:              4,
			prevButtonStateHandler:   handlePrevButtonState,
			nextButtonStateHandler:   handleNextButtonState
	});
	alert("1");
	if (carousel!=NULL)
	{
		alert("ok");
	}
	else
	{
		alert("not ok");
	}
	
	getContent('home');
}
*/

