/* (c)Scientec Internet Applications + Media GmbH - www.scientec.de */

//document.write('<style type="text/css">#onTEAMcontent{display:none}</style>');

posx = [306,306,256];
wcont = [];
var status = 1;
var amp = 1;
var svgstep = 3;
mouseX = 0;
mouseY = 0;
dragstat = 0;
posXstart = 306; 

function init()
{
  if(!(document.all && navigator.userAgent.indexOf("MSIE 9.0")==-1))
  {
    SVG=document.createElement("object");
    SVG.id="motion";
    SVG.data="/onTEAM/layout/svg/motion.svg";
    SVG.type="image/svg+xml";
    SVG.onload=size;
    document.body.appendChild(SVG);
  }
  //facebook=document.createElement("div");
  //facebook.id="facebook";
  //facebook.innerHTML='<iframe src="http://www.facebook.com/plugins/like.php?href=test.pfeffermotiondesign.de&amp;layout=button_count&amp;show_faces=true&amp;width=67&amp;action=like&amp;font=lucida+grande&amp;colorscheme=dark&amp;height=21 " scrolling="no" frameborder="0" style="border:none; overflow:hidden;width:67px; height:21px;" allowTransparency="true"></iframe>';
  //document.body.appendChild(facebook);


  //$('#onTEAMcontent').addClass('hyphenate');
  //Hyphenator.addExceptions('','PFEFFER')
  //Hyphenator.addExceptions('','MOTION')
  //Hyphenator.addExceptions('','DESIGN')
  //Hyphenator.run();
  //$('#onTEAMcontent').css('display','block');

  Mailto();

  wcont = window.name.split("-!-");
  if (wcont[0] == "pfeffer")
  {
    status = wcont[1];
    posx[0] = wcont[2];
    posx[1] = wcont[3];
    posx[2] = wcont[4];
    setstat(status);
  }
  else
  {
    window.name = "pfeffer-!-1-!-200-!-200-!-150";
    setstat(1);
  }
  var bewegmich = posx[status]*1-24;
  document.getElementById('bewegmich').style.left = bewegmich + 'px';
  document.getElementById('pin').style.left = posx[status] + 'px';
  posXstart = posx[status];
  jump(0);
  
  $('#page').bind("touchmove", function(e) { dragdiv2(e) });
  $('#page').bind("touchend", function(e) { dragstop(e) });
  $('#pin').bind("touchmove", function(e) { dragdiv2(e) });
  $('#pin').bind("touchstart", function(e) { dragstart2(e) });
}

function size()
{
  if (document.body.clientWidth > 1024)
  {
    document.getElementById('motion').contentDocument.getElementById('svgobj').setAttribute("maxwidth",document.body.clientWidth)
  }
  else
  {
    document.getElementById('motion').contentDocument.getElementById('svgobj').setAttribute("maxwidth",1024)
  }
  document.getElementById('motion').contentDocument.getElementById('svgobj').style.height="778px"
}

function flash(param)
{
if (param!=null )alert ("Function flash wurde mit dem Parameter " +param+ " aufgerufen")
else alert ("Function flash wurde ohne Parameter aufgerufen")

}

function Mailto()
{
	$('em.em').each(function(){
		var EM = $(this).text().replace(/~at~/i,"@");
		$(this).html('<a href="mailto:'+EM+'">'+EM+'</a>');
	});
}

function setstat(cstat)
{
  status = cstat;
  document.getElementById('pin').style.left = posx[status] + 'px';
  var bewegmich = posx[status]*1-24;
  document.getElementById('bewegmich').style.left = bewegmich + 'px';
  document.getElementById('status0').className = '';
  document.getElementById('status1').className = '';
  document.getElementById('status2').className = '';
  document.getElementById('status'+status).className = 'aktiv';
  window.name = "pfeffer-!-"+status+"-!-"+posx[0]+"-!-"+posx[1]+"-!-"+posx[2];
}

function jump(xstep)
{
  if (posXstart*1 + xstep*1 < 256)
  {
    xstep = 256 - posXstart;
  }
  if (posXstart*1 + xstep*1 > 406)
  {
    xstep = 406 - posXstart;
  }
  posx[status] = posXstart*1 + xstep*1;
  svgstep = (posx[1]-256)*(posx[1]-256)*3/2500;
  amp = (posx[0]*1-256)*1/50;
  g1r = parseInt(228 - (posx[2]-256)*42/150);
  g1g = parseInt(228 - (posx[2]-256)*223/150);
  g1b = parseInt(228 - (posx[2]-256)*74/150);
  g2r = parseInt(216 - (posx[2]-256)*30/150);
  g2g = parseInt(216 - (posx[2]-256)*211/150);
  g2b = parseInt(216 - (posx[2]-256)*62/150);
  g3r = parseInt(202 - (posx[2]-256)*16/150);
  g3g = parseInt(202 - (posx[2]-256)*197/150);
  g3b = parseInt(202 - (posx[2]-256)*48/150);
  document.getElementById('pin').style.left = posx[status] + 'px';
  window.name = "pfeffer-!-"+status+"-!-"+posx[0]+"-!-"+posx[1]+"-!-"+posx[2];
}

function dragstart()
{
  dragstat = 1;
  mouseXstart = mouseX;
  posXstart = document.getElementById('pin').style.left.replace("px","");
  return false;
}
function dragstart2(e)
{
  dragstat = 1;
 
  var orig = e.originalEvent;
  mouseX = orig.changedTouches[0].pageX;  
  mouseXstart = mouseX;
  
  posXstart = document.getElementById('pin').style.left.replace("px","");
  return false;
}

function dragdiv()
{
  if (dragstat)
  {
    document.getElementById('bewegmich').style.display='none';
    jump(mouseX-mouseXstart);
  }
}
function dragdiv2(e)
{
  if (dragstat)
  {
    document.getElementById('bewegmich').style.display='none';
    
    e.preventDefault();  
    var orig = e.originalEvent;
    mouseX = orig.changedTouches[0].pageX;  
    jump(mouseX-mouseXstart);
  }
}
function dragstop()
{
  dragstat = 0;
  return false;
}

if (!(document.all && navigator.userAgent.indexOf("MSIE 9.0")==-1))
{
  document.addEventListener("mousemove", function(e){getMouseXY(e)}, true);
}

function getMouseXY(e){
 	if(document.all){
		mouseX = window.event.clientX;
		mouseY = window.event.clientY;
	}
	else
	{
		mouseX = e.clientX;
		mouseY = e.clientY;
	}
}

