$(document).ready(function () {
		
		
	/* Set the initial height of #content container in order to display people backgrounds at as full height as possible */
	var navHeight = $("#navigation").height();
	var windowHeight = $(window).height();
	
	if (navHeight >= windowHeight) {
		$("#home #content, body.profiles #content").css("min-height", navHeight);
	}
	else {
		$("#home #content, body.profiles #content").css("min-height", windowHeight);
	}

	
	/*	If the User resizes the window, adjust the #content container height */
	$(window).bind("resize", resizeWindow);
	
	
	/* IE6 transparent images */
	$(window).load(transparentPNGs);

	function transparentPNGs() {
		if ($.browser.msie && $.browser.version <= 6) {
			$.each($("img"), function (foo, img) {
				if (img.src.indexOf(".png") > -1 && img.width && img.height) {
					img.style.width = img.width + "px";
					img.style.height = img.height + "px";
					img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img.src + "', sizingMethod='scale')";
					img.src = '/images/x.gif';
				}
			});
		}
	}
	


    $("#verification_1").click(function () {
       // alert("ok");
    });

    /* popup windows */
		$("a.external, a.pdf").click(function () {
			window.open($(this).attr("href"));
					return false;
		});




	/*	ts and cs */
	$("a.terms").click(function () {
								 
			/* display terms in a pop up window if we're on a vote screen and in IE6/7 */					 
			var thisHref = window.location.href;		 
			var thisHref = thisHref.substring(thisHref.lastIndexOf("/")+1);
				
				
			if (thisHref == "vote" && $.browser.msie && $.browser.version <= 7)	{
				
				newwindow=window.open("/terms",'popwindow','height=600,width=600,scrollbars=1');
				return false;
				
			}
			else {
					
			/* remove prizes box if it already exists */
			$("#prizes-box-wrap").remove();	 
									 
			$("#content").append('<div id="terms-box-wrap"><h4>Terms and Conditions <span id="close-terms">X Close</span></h4><div id="terms-box"></div></div>');
	
			$('#terms-box-wrap').vCenter();
	
			$('#terms-box').jScrollPane();
	
			reinitialiseScrollPane = function() {
					$('#terms-box').jScrollPane({scrollbarWidth:6, scrollbarMargin:16, showArrows:true, arrowSize: 16});
			}
	
			/* Ajax load */
			$("#terms-box").load("/terms #body-content", reinitialiseScrollPane);
	
	
			/*	 Naughty IE6 gets z-index select fix */
			if ($.browser.msie && $.browser.version <= 6) {
				$('#terms-box-wrap').bgiframe();
			}
	
	
			$("#close-terms").click(function () {
				$("#terms-box-wrap").remove();
			});
	
			$("#terms-box-wrap").show();

			return false;
		}//end else
	});



	/*	set checkbox styles */
	if ($.browser.msie && $.browser.version <= 7) {
		$("form :checkbox").css("margin-left", "-3px");
	}

	else {
		$("form :checkbox").css("margin-left", "1px");
	};


	/*	form info bubble */
	$("div.emailinfo label").toggle(function () {
			$("div.emailinfo").append("<div class='info-bubble'>By providing your email address you agree to receive email communications from Volkswagen.</div>");
		}, function () {
		  $("div.info-bubble").remove();
		  
	 });


	/* Load the tick image over first thumbnail at page load*/
	$("ul.video-thumbs li:first-child a").prepend('<img id="tick" src="/images/reviewers/tick.png" alt="Video loaded" title="Video loaded" />');

	$("ul.video-thumbs a").click(function () {
										   
		loadVideo(this.href);							   
										   
		if ($('ul.video-thumbs #tick').length) {
			$('#tick').remove();
			$(this).prepend('<img id="tick" src="/images/reviewers/tick.png" alt="Video loaded" title="Video loaded"  />');
		} else {
			$(this).prepend('<img id="tick" src="/images/reviewers/tick.png" alt="Video loaded" title="Video loaded"  />');
		}
		
		transparentPNGs();
		return false;
	});



}); //ends document.ready







function loadVideo(vid) {

		var theURL = vid;
		var videoId = theURL.substring(theURL.lastIndexOf("=")+1);
		
		var params = {allowScriptAccess: "always", allowfullscreen: "true", bgcolor: "#000000", wmode: "transparent" };
		var atts = { id: "profile-video-flash"};
		swfobject.embedSWF("http://www.youtube.com/v/" + videoId + "&hl=en&fs=1&rel=0&enablejsapi=1&playerapiid=ytplayer&autoplay=1", "profile-video-flash", "320", "265", "8", null, null, params, atts);	

		return false;
}




(function($) {
  $.fn.vCenter = function(options) {
 	var pos = {
   		sTop : function() {
		  return window.pageYOffset
		  || document.documentElement && document.documentElement.scrollTop
		  ||  document.body.scrollTop;
		   },
		   wHeight : function() {
		  return window.innerHeight
		  || document.documentElement && document.documentElement.clientHeight
		  || document.body.clientHeight;
		   }
 		};
 		return this.each(function(index) {
		   if (index == 0) {
		  var $this = $(this);
		  var elHeight = $this.height();
		  var elTop = pos.sTop() + (pos.wHeight() / 2) - (elHeight / 2);
		  $this.css({
			position: 'absolute',
			marginTop: '0',
			top: elTop
		  });
		}
 	});
 };
 })(jQuery);


	
function resizeWindow( e ) {
		var navHeight = $("#home #navigation").height();
		var windowHeight = $(window).height();
		
		if (navHeight >= windowHeight) {
			$("#home #content").height(navHeight);
		}
		else {
			$("#home #content").height(windowHeight);
		}
}









/**
 * When the open event is called, this function will be used to 'open'
 * the overlay, container and data portions of the modal dialog.
 *
 * onOpen callbacks need to handle 'opening' the overlay, container
 * and data.
 */
function modalOpen (dialog) {
	
	dialog.overlay.fadeIn('slow', function () {
		dialog.container.fadeIn('slow', function () {
			//dialog.data.hide().slideDown('slow');	
						dialog.data.show();	
		});
	});
}
















