function fieldFocus(element, text)
{
	if(text == element.value) {
		element.value = "";
	}
}
function fieldBlur(element, text)
{
	if("" == element.value) {
		element.value = text;
	}
}			

jQuery(document).ready(function(){
	
	//jQuery('#backgroundContainer').jparallax({frameDuration: 40});
	setDominos();
	setAlbum_player();
	setDominosVideo();
});

onresize = function() {
	//jQuery('#backgroundContainer').jparallax({frameDuration: 40});
	setKeexBlog();
	setDominos();
	setAlbum_player();
	setDominosVideo();
}

function ahah(url,target) {
    //document.getElementById(target).innerHTML = '';
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = function() {ahahDone(target);};
        req.open("GET", url, true);
        req.send(null);
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = function() {ahahDone(target);};
            req.open("GET", url, true);
            req.send();
        }
    }
} 

function ahahDone(target) {
   // only if req is "loaded"
   if (req.readyState == 4) {
       // only if "OK"
       if (req.status == 200 || req.status == 304) {
           results = req.responseText;
           document.getElementById(target).style.top = "0px";
           document.getElementById(target).innerHTML = results;
           
           setDominosVideo();
           setKeexBlog();
           setDominos();
           setAlbum_player();
           
       } else {
           //document.getElementById(target).innerHTML="ahah error:\n" + req.statusText;
       }
   }
}

function setKeexBlog() {
	
	if(document.getElementById('keexblog')) {
		var keexblog = document.getElementById('keexblog');
		var photocontainer = document.getElementById('photocontainer');
		var sidebar = document.getElementById('sidebar');
		keexblog.style.width = photocontainer.offsetWidth + 'px';
		keexblog.style.height = sidebar.offsetHeight + 'px';
   }     
	
}

function setDominos() {
	
	if(document.getElementById('dominos')) {
		var dominos = document.getElementById('dominos');
		var dominos_image = document.getElementById('dominos_image');
		var photocontainer = document.getElementById('photocontainer');
		var sidebar = document.getElementById('sidebar');
		var newWidth = photocontainer.offsetWidth;
		var newHeight = sidebar.offsetHeight;
		
		var new_image_height = newHeight;
		
		var new_image_width = new_image_height * (900/1289);
		
		if(new_image_width < (newWidth)) { 
			new_image_width = newWidth;
			new_image_height = new_image_width * (1289/900);
			left = ((newWidth / 2) - (new_image_width / 2));
			right = ((newWidth / 2) - (new_image_width / 2));
		}
		
		dominos.style.width = newWidth + 'px';
		dominos.style.height = newHeight + 'px';
		
		dominos_image.style.width = new_image_width + 'px';
		dominos_image.style.height = new_image_height + 'px';
		
   }
           
	
}

function setAlbum_player() {
	
	if(document.getElementById('album_player')) {
		var album_player = document.getElementById('album_player');
		var album_player_image = document.getElementById('album_player_image');
		var photocontainer = document.getElementById('photocontainer');
		var sidebar = document.getElementById('sidebar');
		var newWidth = photocontainer.offsetWidth;
		var newHeight = sidebar.offsetHeight;
		
		var new_image_height = newHeight;
		
		var new_image_width = new_image_height * (841/832);
		
		var left = ((newWidth / 2) - (new_image_width / 2));
		
		if(new_image_width < (newWidth)) { 
			new_image_width = newWidth;
			new_image_height = new_image_width * (832/841);
			left = 0;
		}
		
		album_player.style.width = newWidth + 'px';
		album_player.style.height = newHeight + 'px';
		
		album_player_image.style.width = new_image_width + 'px';
		album_player_image.style.height = new_image_height + 'px';
		
		album_player_image.style.left = left + 'px';
		
		var album_player_content = document.getElementById('album_player_content');
		if(newHeight < 650) {
			
			album_player_content.style.bottom = 15 + 'px';
			album_player_content.style.top = 'auto';
			album_player_content.style.marginTop = 0 + 'px';
		} else {
			album_player_content.style.bottom = 'auto';
			album_player_content.style.top = '50%';
			album_player_content.style.marginTop = '-325px';
		}
   }
           
	
}

function setDominosVideo() {
	
	if(document.getElementById('dominos_video')) {
		
		if(!document.getElementById('videoplayer')) {
			var s1 = new SWFObject("player.swf","videoplayer","500","400","9","#FFFFFF");
			s1.addParam("allowfullscreen","true");
			s1.addParam("allownetworking","all");
			s1.addParam("allowscriptaccess","always");
			//s1.addParam("wmode","opaque");
			s1.addParam("flashvars","file=video/dominos_clip.flv&controlbar=none&autostart=true&stretching=fill&displayclick=none&bufferlength=3");
			s1.write("video_preview");
		}
		
		var dominos = document.getElementById('dominos_video');
		var video_preview = document.getElementById('video_preview');
		var dominos_image = document.getElementById('dominos_image');
		var videoplayer = document.getElementById('videoplayer');
		var photocontainer = document.getElementById('photocontainer');
		var sidebar = document.getElementById('sidebar');
		var newWidth = photocontainer.offsetWidth;
		var newHeight = sidebar.offsetHeight;
		
		var new_image_height = newHeight;
		
		var new_image_width = new_image_height * (900/1289);
		
		if(new_image_width < (newWidth)) { 
			new_image_width = newWidth;
			new_image_height = new_image_width * (1289/900);
			left = ((newWidth / 2) - (new_image_width / 2));
			right = ((newWidth / 2) - (new_image_width / 2));
		}
		
		dominos.style.width = newWidth + 'px';
		dominos.style.height = newHeight + 'px';
		
		dominos_image.style.width = new_image_width + 'px';
		dominos_image.style.height = new_image_height + 'px';
		
		video_preview.style.width = newWidth + 'px';
		video_preview.style.height = newHeight + 'px';
		
		videoplayer.style.width = newWidth + 'px';
		videoplayer.style.height = newHeight + 'px';
		window.setTimeout('showDominosVideoImage()', 14000);
   }
           
	
}

function showDominosVideoImage() {
	var dominos_image = document.getElementById('dominos_image');
	$("#dominos_image").animate({ 
			opacity: "1"
		  }, 2000 , "linear", function(){$("#video_preview").css({display: 'none'});} );
}

function photoClick(type) {
	
	var yourphotos = document.getElementById("yourphotos");
	var ourphotos = document.getElementById("ourphotos");
	var foundphotos = document.getElementById("foundphotos");
	var photocontainer = document.getElementById("photocontainer");
	var yourPhotosNotice = document.getElementById("yourPhotosNotice");
	
	var listenlink = document.getElementById("listenlink");
	
	if(type == 'yourphotos') {
		ahah('http://musicfromthebigpink.com/photos_yours', 'photocontainer');
		yourphotos.setAttribute('class', 'selected');
		ourphotos.setAttribute('class', '');
		foundphotos.setAttribute('class', '');
		listenlink.setAttribute('class', '');
		yourphotos.setAttribute('className', 'selected');
		ourphotos.setAttribute('className', '');
		foundphotos.setAttribute('className', '');
		listenlink.setAttribute('className', '');
		yourPhotosNotice.style.bottom = "20px";
	} else if(type == 'ourphotos') {
		ahah('http://musicfromthebigpink.com/photos_ours', 'photocontainer');
		yourphotos.setAttribute('class', '');
		ourphotos.setAttribute('class', 'selected');
		foundphotos.setAttribute('class', '');
		listenlink.setAttribute('class', '');
		yourphotos.setAttribute('className', '');
		ourphotos.setAttribute('className', 'selected');
		foundphotos.setAttribute('className', '');
		listenlink.setAttribute('className', '');
		yourPhotosNotice.style.bottom = "-200px";
	} else if(type == 'foundphotos') {
		ahah('http://musicfromthebigpink.com/photos_found', 'photocontainer');
		yourphotos.setAttribute('class', '');
		ourphotos.setAttribute('class', '');
		foundphotos.setAttribute('class', 'selected');
		listenlink.setAttribute('class', '');
		yourphotos.setAttribute('className', '');
		ourphotos.setAttribute('className', '');
		foundphotos.setAttribute('className', 'selected');
		listenlink.setAttribute('className', '');
		yourPhotosNotice.style.bottom = "-200px";
	} else if(type == 'listen') {
		ahah('http://musicfromthebigpink.com/album_player', 'photocontainer');
		yourphotos.setAttribute('class', '');
		ourphotos.setAttribute('class', '');
		foundphotos.setAttribute('class', '');
		listenlink.setAttribute('class', 'selected');
		yourphotos.setAttribute('className', '');
		ourphotos.setAttribute('className', '');
		foundphotos.setAttribute('className', '');
		listenlink.setAttribute('className', 'selected');
		yourPhotosNotice.style.bottom = "-200px";
	}
	
}

function toggleComments() {
	
	if($("#facebook_comments").css("right")!="-310px") {
		
		$("#facebook_comments").css({display: 'block'});
		$("#facebook_comments").animate({ 
			right: "-310px"
		  }, 500 );
		
		
		
	} else {
		
		$("#facebook_comments").animate({ 
			right: "60px"
		  }, 500, "linear", function(){$("#facebook_comments").css({display: 'none'});} );
	}
}

var comments_once = false;

function showComments() {
	
	if(!comments_once) {
		$("#facebook_comments").css({display: 'block'});
			$("#facebook_comments").animate({ 
				right: "-310px"
			  }, 500 );
	}
	
	comments_once = true;
}





//*****************************************************************************
// Do not remove this notice.
//
// Copyright 2001 by Mike Hall.
// See http://www.brainjar.com for terms of use.
//*****************************************************************************

// 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;
  }
}

var browser = new Browser();

// Global object to hold drag information.

var dragObj = new Object();
dragObj.zIndex = 0;

function dragStart(event, id) {
	
	// don't want dominos images draggable
	if(document.getElementById('dominos')) {
		return;
	}
	
	if(document.getElementById('album_player')) {
		return;
	}
	
	if(document.getElementById('dominos_video')) {
		return;
	}
	
  var el;
  var x, y;

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

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

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

    if (dragObj.elNode.nodeType == 3)
      dragObj.elNode = dragObj.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.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

  // Update element's z-index.

  dragObj.elNode.style.zIndex = ++dragObj.zIndex;

  // Capture mousemove and mouseup events on the page.

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

function dragGo(event) {

  var x, y;

  // 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.
	
	
  	// check if we're dragging off the top
  	
  	var newtop = (dragObj.elStartTop  + y - dragObj.cursorStartY);
  	
	if(newtop < 0) {
		// check if we're dragging off the bottom
		var photocontainer = document.getElementById("photocontainer");
		var photoheight = photocontainer.offsetHeight;
		
		var myWidth = 0, myHeight = 0;
		if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
		   myWidth = window.innerWidth;
		   myHeight = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		}
		
		if(newtop > -(photoheight - myHeight)) {
			dragObj.elNode.style.top  = newtop + "px";
		}
	} else {
		dragObj.elNode.style.top  = "0px";
	}

  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();
}

function dragStop(event) {

  // Stop capturing mousemove and mouseup events.

  if (browser.isIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",   dragStop);
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragGo,   true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
}