var isFlashActive = false;
var is_expand = false;
function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
	
function getTagFlash(w, h, file, version, id, wmode, vars) {
	// may need to update version setting to handle version 7
	var fString = '';
	if (file != "") {	
	// if the filename has a querystring use & to add to it
	var qs = (file.indexOf("?")>-1) ? "&" : "?";
	var d = new Date();
	file = file + qs + "timeStamp=" + d.getMonth() + d.getDate() + d.getFullYear() + d.getHours(); 
	switch (version) {
		case 7:
			minorVersion = 19;
			break;
		case 6:
			minorVersion = 79;
			break;
		case 5:
			minorVersion = 30;
			break;
		default:
			minorVersion = 0;
	}
	fString += '<div id="flashwrap">' ;
	fString += '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+ version +',0,'+ minorVersion +',0"';
	fString += 'WIDTH="'+w+'" HEIGHT="'+h+'" id="'+id+'" ALIGN="" allowscriptaccess="always">';
	fString += '<PARAM NAME=movie VALUE="'+file+'"> <PARAM NAME=loop VALUE=false> <PARAM NAME=quality VALUE=high> <PARAM NAME=wmode VALUE='+wmode+'>';
	fString += '<PARAM NAME=FlashVars VALUE="'+vars+'">';
	fString += '<PARAM NAME="allowScriptAccess" VALUE="always">';
	fString += '<EMBED src="'+file+'" loop="false" quality="high" wmode="'+wmode+'" WIDTH="'+w+'" HEIGHT="'+h+'" NAME="'+id+'" FlashVars="'+vars+'" ALIGN=""';
	fString += 'TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer" allowscriptaccess="always"></EMBED></OBJECT>';
	fString += '</div>';
	}
	return fString;
}

	function resizeMe()
	{
 
		var coors = findPos($('slide'));
		//$('flashLayer').setStyle({top: (coors[1]) + 'px', left: (coors[0]-500) + 'px', width: '865px', height: '410px'});
		if(is_expand){
		  $('flashLayer').setStyle({top: (coors[1]) + 'px', left: (coors[0]-500) + 'px', width: '865px', height: '410px'});
    }else{
		  $('flashLayer').setStyle({top: (coors[1]) + 'px', left: (coors[0]-500) + 'px', width: '466px', height: '410px'});
    
    }
	}

	function extendFlash()
	{
 
		var coors = findPos($('slide'));		
		if (!isFlashActive)
		{
			isFlashActive = true;
			$('flashLayer').morph({top: (coors[1]) + 'px', left: (coors[0]-500) + 'px', width: '865px', height: '410px'},{duration: 0.5});
		}
	}
	
	function retractFlash()
	{
 
		if (isFlashActive)
		{
			isFlashActive = false;
			$('flashLayer').setStyle({top: coors[1] + 'px', left: coors[0] + 'px', width: '865px', height: '410px'});
		}
	}
	
	function	boot(startOn)
	{
		var coors = findPos($('slide'));
		var swfString = getTagFlash("966", "410", "/flash/compas_v15.swf", 6, 'flashOverlay', 'transparent', 'startOn=' + startOn);
		$('flashLayer').setStyle({top: coors[1] + 'px', left: (coors[0]-500) + 'px', width: '865px', height: '410px'});
		$('flashLayer').setStyle({display: 'inline', overflow: 'hidden'});
		$('flashLayer').innerHTML = swfString;
		
		if(!document.all){
      // stupid fix when user click on the right flash
      //$('flashwrap').onclick = flashwrap_expand;
 
      flashwrap_collapse();
	  }
	}
	
	
	function flashwrap_expand(){
    is_expand = true;

    $('flashLayer').setStyle({'width':'966px','overflow':'hidden','marginLeft':'0'}); 		
	  $('flashwrap').setStyle({'width':'966px','marginLeft':'0'});
   // alert("Expanded");	    
	}
	function flashwrap_collapse(){
    is_expand = false;
 
	  
    $('flashLayer').setStyle({'width':'466px','overflow':'hidden','marginLeft':'500px'}); 		
	  $('flashwrap').setStyle({'width':'966px','marginLeft':'-500px'});
	  //alert("Collapsed");
	}
	
	
