function getHTTPObject() {
	var xhr = false;//set to false, so if it fails, do nothing
	if(window.XMLHttpRequest) {//detect to see if browser allows this method
		var xhr = new XMLHttpRequest();//set var the new request
	} else if(window.ActiveXObject) {//detect to see if browser allows this method
		try {
			var xhr = new ActiveXObject("Msxml2.XMLHTTP");//try this method first
		} catch(e) {//if it fails move onto the next
			try {
				var xhr = new ActiveXObject("Microsoft.XMLHTTP");//try this method next
			} catch(e) {//if that also fails return false.
				xhr = false;
			}
		}
	}
	return xhr;//return the value of xhr
}

function login() {
    var username = document.getElementById("strUserName").value;
    var password = document.getElementById("strPassword").value;
    http.open("get", "login.php", false, username, password);
    http.send("");
    if (http.status == 200) {
        document.location = "#";
    } else {
        alert("Incorrect username and/or password.");
    }
    return false;
}

function helpInvisible () {

	if (document.getElementById) { // DOM3 = IE5, NS6 
		document.getElementById('clickAndDragHelp').style.visibility = 'hidden'; 
	} else { 
		if (document.layers) { // Netscape 4 
			document.clickAndDragHelp.visibility = 'hidden'; 
		} else { // IE 4 
			document.all.clickAndDragHelp.style.visibility = 'hidden'; 
		} 
	}
	
}

function helpVisible () {
	
		if (document.getElementById) { // DOM3 = IE5, NS6 
			document.getElementById('clickAndDragHelp').style.visibility = 'visible'; 
		} else { 
			if (document.layers) { // Netscape 4 
				document.clickAndDragHelp.visibility = 'visible'; 
			} else { // IE 4 
				document.all.clickAndDragHelp.style.visibility = 'visible'; 
			} 
		}
		
}

function hideHelp (event) {
	helpInvisible();
	dragHelpStop (event);
	//clearInterval (helpInterval);
}

function showHelp (event) {
	if (!helpDone)
		helpVisible();
	if (!isHelped) {
		isHelped = 1;
		myHelpEvent = event;
		dragHelpStart (myHelpEvent, 'clickAndDragHelp');
		//helpInterval = setInterval ('moveHelp()', 1);
		helpTimeout = setTimeout ('hideHelp(myHelpEvent)', 10000);
	}
}

// Determine browser and version.

function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

function dragHelpStop(event) {

  // Stop capturing mousemove and mouseup events.

  helpDone = 1;
  if (browser.isIE) {
    document.detachEvent("onmousemove", dragHelpGo);
    document.detachEvent("onmouseup",   dragHelpStop);
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragHelpGo,   true);
    document.removeEventListener("mouseup",   dragHelpStop, true);
  }
}

function dragHelpGo(event) {

  var x, y, topVal, leftVal;

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Move drag element by the same amount the cursor has moved.

  topVal = dragHelp.elStartTop  + y - dragHelp.cursorStartY;
  leftVal = dragHelp.elStartLeft + x - dragHelp.cursorStartX;
  
  /*
  if (topVal < 50)
  	topVal = 50;
  if (topVal > 420)
  	topVal = 420;
	*/

  dragHelp.elNode.style.left =
    leftVal + "px";
  dragHelp.elNode.style.top  =
    topVal + "px";
	
  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();
	
}

function dragHelpStart (event, id) {

  var el;
  var x, y;

  // If an element id was given, find it. Otherwise use the element being
  // clicked on.

  if (id)
    dragHelp.elNode = document.getElementById(id);
  else {
    if (browser.isIE)
      dragHelp.elNode = window.event.srcElement;
    if (browser.isNS)
      dragHelp.elNode = event.target;

    // If this is a text node, use its parent element.

    if (dragHelp.elNode.nodeType == 3)
      dragHelp.elNode = dragHelp.elNode.parentNode;
   }
   
   // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }
  
  // Save starting positions of cursor and element.
  
  dragHelp.cursorStartX = 81;
  dragHelp.cursorStartY = 81;
  
  dragHelp.elStartLeft = 0;
  dragHelp.elStartTop  = 0;

  if (browser.isIE) {
    document.attachEvent("onmousemove", dragHelpGo);
    document.attachEvent("onmouseup",   dragHelpStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", dragHelpGo,   true);
    document.addEventListener("mouseup",   dragHelpStop, true);
    event.preventDefault();
  }

}



// iDevice slideshow (screens of actual app within mobile phone frame)

src = ["http://qyoo_website.s3.amazonaws.com/screens/1.jpg", "http://qyoo_website.s3.amazonaws.com/screens/2.jpg", "http://qyoo_website.s3.amazonaws.com/screens/3.jpg", "http://qyoo_website.s3.amazonaws.com/screens/4.jpg", "http://qyoo_website.s3.amazonaws.com/screens/5.jpg"]
duration = 4;
 
screens=[]; ct=0;
function switchScreen() {
	var n=(ct+1)%src.length;
	if (screens[n] && (screens[n].complete || screens[n].complete==null)) {
		document["Mobile_Screenshot"].src = screens[ct=n].src;
	}
	screens[n=(ct+1)%src.length] = new Image;
	screens[n].src = src[n];
	setTimeout("switchScreen()",duration*1000);
}
onload = function(){
	if (document.images)
		switchScreen();
}

/* Everyone scroller */

function changeQyooFor () {

	$("span#everyone").animate({opacity:0}, 300, 'linear', function() {
      $(this).html(arrQyooFor[intQyooFor++]);
    }).animate({opacity:1}, 300);
	
	if (intQyooFor >= 11)
		clearInterval (qyooFor);
}

// Contact form page scroll

function pageScrollTo(strDiv) {
	/*
	var contact = document.getElementById ("contact");
    contact.scrollIntoView (true);
	*/
	$.scrollTo (strDiv, 500, {});
}

function showModal(modalDiv) {
	$(modalDiv).modal({
		overlayClose:true,
		opacity: 80,
		overlayCss: {backgroundColor:"#fff"},
		onOpen: function (dialog) {
			dialog.overlay.fadeIn('slow', function () {
				dialog.container.slideDown('slow', function () {
					dialog.data.fadeIn('slow');
				});
			});
		},
		onClose: function (dialog) {
			dialog.data.fadeOut('slow', function () {
				dialog.container.slideUp('slow', function () {
					dialog.overlay.fadeOut('slow', function () {
						$.modal.close(); // must call this!
					});
				});
			});
	}});
}


jQuery(function( $ ){
	
	$.localScroll({
		target:'#content',
		axis:'x',
		event:'click',
		offset: {
			left: -200
		}
	});
	
	// Scroll initially if there's a hash (#something) in the url 
	$.localScroll.hash({
		target: '#content',
		axis:'x',
		offset: {
			left: -200
		}
	});
	
	
	$('#content').
		dragscrollable({acceptPropagatedEvent: true});
		
		
	$('#news_scroller').
		dragscrollable({acceptPropagatedEvent: true});
	 
	
	
});


// global variables

var helpDone = 0;
var isHelped = 0;
var http = getHTTPObject();
var helpTimeout;
var myHelpEvent;
var browser = new Browser();
// Global object to hold drag information.
var dragSlider = new Object();
var dragHelp = new Object();

var intQyooFor = 0;
var arrQyooFor = new Array ("Marketers", "Agencies", "Planners", "Publishers", "Creatives", "Designers", "DBAs", "Analysts", "You", "Me", "Anyone", "Everyone");			
var qyooFor = setInterval ("changeQyooFor()", 1400);