// JavaScript Document
//mode 0 more 1 back
function more(display_size,total,mode,cur_end)
{
	var out_html="<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" id=\"main_img_table\"><tr>";
	var more="";
	var new_end="";
	if (!mode)//more
	{
		new_end=display_size+cur_end;
		if ((cur_end)>0)//back
			out_html+="<td><img src=\"/portfolio/back.gif\" alt=\"more testimonial\" onclick=\"more("+display_size+","+total+",1,"+new_end+")\"></td>";
		if (total<=new_end)	new_end=total;
		else	more="<td><img src=\"/portfolio/more.gif\" alt=\"more testimonial\" onclick=\"more("+display_size+","+total+",0,"+new_end+")\"></td>";
		for(var i=(1+cur_end);i<=new_end;i++)
			out_html+="<td><div><img src=\"/portfolio/"+i+".gif\" alt=\"\" onMouseOver=\"enlarge_img(this,"+i+",1);\" onMouseOut=\"enlarge_img(this,"+i+",0);\" onClick=\"play_testimonial("+i+",this)\"></div></td>"; 
		out_html+=more+"</tr></table>";
		document.getElementById("portfolio_nav").innerHTML=out_html;
	}
	else
	{
		new_end=cur_end-display_size;
		if (new_end>display_size)//back
			out_html+="<td><img src=\"/portfolio/back.gif\" alt=\"more testimonial\" onclick=\"more("+display_size+","+total+",1,"+new_end+")\"></td>";
		if (total<new_end)	new_end=total;
		else	more="<td><img src=\"/portfolio/more.gif\" alt=\"more testimonial\" onclick=\"more("+display_size+","+total+",0,"+new_end+")\"></td>";
		for(var i=(1+new_end-display_size);i<=new_end;i++)
			out_html+="<td><div><img src=\"/portfolio/"+i+".gif\" alt=\"\" onMouseOver=\"enlarge_img(this,"+i+",1);\" onMouseOut=\"enlarge_img(this,"+i+",0);\" onClick=\"play_testimonial("+i+",this)\"></div></td>"; 
		out_html+=more+"</tr></table>";
		document.getElementById("portfolio_nav").innerHTML=out_html;
	}
}
var cur_playing_img_id;
var cur_playing_obj;
function enlarge_img(obj,id,mode)
{
	if (mode)//over
	{
		
		obj.src="/portfolio/"+id+"_over.gif";	
		obj.style.position="absolute";
		obj.style.top="-5px";
		obj.style.left="0px";
	}
	else
	{
		if (id!=cur_playing_img_id)
		{
			obj.src="/portfolio/"+id+".gif";
			obj.style.position="static";
			obj.style.top=0;
			obj.style.left=0;
		}
	}
	/*
	if (obj.src.substring(obj.src.length-8)!="over.png")
	{		
		
		if (cur_obj) 
		{
			cur_obj.src="/portfolio/"+cur_img_name+".gif";
			cur_obj.style.position="static";
			cur_obj.style.top=0;
			cur_obj.style.left=0;
		}
		cur_obj=obj;
		cur_img_name=the_name;
		
		obj=obj;
		obj.src="/portfolio/"+cur_img_name+"_over.gif";	
		obj.style.position="absolute";
		obj.style.top="-5px";
		obj.style.left="0px";
		
	}
	*/
}
/*
var cur_img_name;
var cur_obj;
function enlarge_img(obj,the_name)
{
	if (obj.src.substring(obj.src.length-8)!="over.png")
	{		
		
		if (cur_obj) 
		{
			cur_obj.src="/portfolio/"+cur_img_name+".gif";
			cur_obj.style.position="static";
			cur_obj.style.top=0;
			cur_obj.style.left=0;
		}
		cur_obj=obj;
		cur_img_name=the_name;
		
		obj=obj;
		obj.src="/portfolio/"+cur_img_name+"_over.gif";	
		obj.style.position="absolute";
		obj.style.top="-5px";
		obj.style.left="0px";
		
	}
}
*/
function play_testimonial(video_id,obj)
{
	if (!cur_playing_obj)	
	{
		cur_playing_obj=document.getElementById('portfolio_1');//remove after get the video of the page
		cur_playing_img_id=1;
	}
	
	if (cur_playing_obj) 
	{
		cur_playing_obj.src="/portfolio/"+cur_playing_img_id+".gif";
		cur_playing_obj.style.position="static";
		cur_playing_obj.style.top=0;
		cur_playing_obj.style.left=0;
	}
	cur_playing_obj=obj;
	cur_playing_img_id=video_id;
	//--------------------------------------------
	var xml_id=video_id-1;
	var the_xml_point=parseXML((xml_id));		
	if (the_xml_point.getElementsByTagName("my_video")[xml_id])
	{
		var parent=document.getElementById("page_video");	
		parent.style.backgroundImage="url("+the_xml_point.getElementsByTagName("bg")[xml_id].childNodes[0].nodeValue+")";
		//add image link
		if (document.getElementById('the_site_link_img'))	document.getElementById("video_main").removeChild(document.getElementById('the_site_link_img'));
		
		var the_link = document.createElement("a");
		the_link.id="the_site_link_img";
		if (navigator.userAgent.indexOf("MSIE")!=-1)//IE
			the_link.style.cssText="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale src='"+the_xml_point.getElementsByTagName("site_img")[xml_id].childNodes[0].nodeValue+"')";
		else	the_link.style.cssText="background-image:url("+the_xml_point.getElementsByTagName("site_img")[xml_id].childNodes[0].nodeValue+")";				
		the_link.style.backgroundRepeat ="no-repeat";
		the_link.style.width="320px";
		the_link.style.height="205px";
		the_link.style.cursor="pointer";
		the_link.style.position="absolute";		
		
		if (the_xml_point.getElementsByTagName("name")[xml_id].childNodes[0].nodeValue=="TorontoDefence")
			the_link.style.top="175px";
		else the_link.style.top="160px";
		if (the_xml_point.getElementsByTagName("name")[xml_id].childNodes[0].nodeValue=="TorontoDefence")
			the_link.style.left="2px";
		else if(the_xml_point.getElementsByTagName("name")[xml_id].childNodes[0].nodeValue=="SmileStylist")
			the_link.style.left="0";
		else	the_link.style.left="60px";
		the_link.href=the_xml_point.getElementsByTagName("site_url")[xml_id].childNodes[0].nodeValue;
		the_link.target="_blank";
		the_link.onclick=function (){
			document.getElementById("page_video").innerHTML=document.getElementById("page_video").innerHTML;			
			};
		
		document.getElementById("video_main").appendChild(the_link);
		//load main video/image
		if(the_xml_point.getElementsByTagName("type")[xml_id].childNodes[0].nodeValue==0)//image
			parent.innerHTML="<img src=\""+the_xml_point.getElementsByTagName("path")[xml_id].childNodes[0].nodeValue+"\" style=\"position:absolute;top:140px;left:505px;\">";
		else//video
			parent.innerHTML="<embed src=\"/players/site_player.swf\" FlashVars=\"isPlay=true&streamName="+the_xml_point.getElementsByTagName("path")[xml_id].childNodes[0].nodeValue+"&video_id="+the_xml_point.getElementsByTagName("name")[xml_id].childNodes[0].nodeValue+"&page_id=testimonial\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"758\" height=\"370\" wmode=\"transparent\" scale=\"noscale\"  salign=\"LT\">";
	}	
}


function parseXML(video_id)
{
	var rssFeed="testimonial.xml";
	try
	{
		if (window.ActiveXObject)
		{
			var errorHappendHere = "Check Browser and security settings";
			xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async=false;
			xmlDoc.load(rssFeed);
		}
		else if(window.XMLHttpRequest)
		{
			
			var errorHappendHere = "Error handling XMLHttpRequest request";
			var d = new XMLHttpRequest();
			d.open("GET", rssFeed, false);
			d.send(null);
			xmlDoc=d.responseXML;
		} else {
			var errorHappendHere = "Error.";
			xmlDoc = document.implementation.createDocument("","",null);
			xmlDoc.async=false;
			xmlDoc.load(rssFeed);
		}
		return xmlDoc;
	}	
	catch(e)
	{
		alert(errorHappendHere);
		return false;
	}
}
function mark_red(obj)
{
	obj.style.color='blue';
}