/*
// ----------------------------------------------------------------------------
//   
//  The Pantechnicon Website Relaunch 2010
//   
//  File:   pt.main.js
//  Creation Date:  07/07/2010
//  Last Modified:  11/07/2010
//   
//  (c)2010 C. Schmidt chris(at)2309(dot)net
// 
// ----------------------------------------------------------------------------
*/

var bg_width = 965;
var myStart=true; 

/* ******************************************************************************************************* */
function set_mrgs () {
	var wdiff =  $(window).width() - bg_width;
	var hdiff =  $(window).height() - $("#main").height();
	if (wdiff>5) var rMrg = wdiff / 2 ; else rMrg = 5;
	$("#main").css("right",rMrg);
	if (hdiff>5) var tMrg = hdiff / 3 ; else tMrg = 5;
	$("#main").css("top",tMrg);
}

/* ******************************************************************************************************* */
function startup_once() { //return;
	   if (myStart) {
	     myStart=false;
	//$("#load").show().fadeOut(900,function(){
		 //$("#backfinal").hide().fadeIn(900);
		 $("#backload").show().fadeOut(1000, function(){ main() });
		 //setTimeout( '$("#main").hide().fadeIn(1800, function(){ main() });',900);
	//});
	   }
}

/* ******************************************************************************************************* */
function slidenext( myobj ) {
	var myact = $(myobj+">img:visible");
	if ( myact.length == 0 ) myact = $(myobj+">img:first");
	var mynext =  myact.next().length ? myact.next() : $(myobj+">img:first");
	mynext.fadeIn(1400);
	myact.fadeOut(1400);	
}

/* ******************************************************************************************************* */
function main() {
	myint = setInterval( function() { slidenext( "#homeview" ) }, 7000 );
}

/* ******************************************************************************************************* */
$(document).ready(function(){  
	
	if ($.browser.msie) { 
		$("#offers span:eq(0)").html("EXPRESS LUNCH");		
		$("#offers span:eq(1)").html("PRE-THEATRE");
	}
	               
	_galsize = ($("#container img").size()+1) * 63;	 
	Cufon.replace(".headline", { fontFamily: 'mFT', hover: true });
	Cufon.replace("#offers,#foot,#join,#tgg,#cubitthouse,.naviname,.pagecontent,.rightvars, .leftvars, #makeres, #banner-msg", { fontFamily: 'mGD', hover: true });
	//$(document).bind("contextmenu",function(e){ return false; }); 
	set_mrgs();
	$("#homeview>img:first").show();
	$("#hireview>img").css({left:'238px'});
	$("#locationview>img").css({left:'238px'});
	$("#chouseview>img").css({left:'238px'});
	$(".rightvars img").css({position:'relative',left:'0px','margin-top':'7px'});
	$(".leftvars img").css({position:'relative',left:'0px','margin-top':'7px'});
	$("#container img").css({position:'relative',left:'0px','margin-left':'3px'});
	$(window).resize(function(){set_mrgs();});
	$("#foot span:eq(1)").click( function(){ window.location.href = 'mailto:reservations@thepantechnicon.com'; }).css('cursor','pointer');
	$("#locationview > .rightvars img:last").click( function(){ window.open( 'http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=The+Pantechnicon,+10+Motcomb+Street,+London,+SW1X+8LA&aq=&sll=51.49968,-0.15651&sspn=0.00748,0.015857&g=10+Motcomb+St,+London+SW1X+8LA,+United+Kingdom&ie=UTF8&hq=The+Pantechnicon,&hnear=10+Motcomb+St,+London+SW1X+8LA,+United+Kingdom&ll=51.49954,-0.156426&spn=0.00748,0.015857&z=16'); }).css('cursor','pointer');
	$("#join,#joinMO").click( function(){ window.open('http://www.cubitthouse.co.uk/?view=work'); }).css('cursor','pointer');
	$("#gallerytext span:last").click( function(){ window.location.href = 'mailto:saskia@cubitthouse.co.uk'; }).css('cursor','pointer');
	$("#load").click(function(){startup_once()});
	$("#locationview .rightvars span:eq(1)").click( function(){ window.location.href = 'mailto:reservation@thepantechnicon.com'; }).css('cursor','pointer');
	$("#locationview .rightvars span:eq(2)").click( function(){ window.open('http://www.thepantechnicon.com'); }).css('cursor','pointer');
	
	
/* ******************************************************************************************************* */	
	$("#navi .navidiv").fadeTo(0,0).first().fadeTo(0,0.5);
	$("#navi .navidiv").hover( function() {
		if ($("#"+$(this).prev().attr("read")+"text").hasClass("hide")) {
			$(this).stop().fadeTo(400, 0.5);
			
		}
	}, function() {
		if ($("#"+$(this).prev().attr("read")+"text").hasClass("hide")||$(this).is(".sub")) {
			$(this).stop().fadeTo(200, 0);
			
		}
	});
	
	$("#joinMO, #join").hover( function() {
		$("#joinMO").stop().fadeTo(400, 0.5);
		
	}, function() {
		$("#joinMO").stop().fadeTo(200, 0);
		
	});
	
/* ******************************************************************************************************* */	
	$("#navi .navidiv:not(.top)").click( function(){
		
		var _thisread = $(this).prev().attr("read");
		mynewreadtext = "#"+_thisread+"text";
		mynewreadview = "#"+_thisread+"view";
		_thisElement = $(this);
		
		if ($("#navi .naviname").filter('.sub').is(":visible") && !$(this).is(".sub")) { 	
			$("#navi .sub").slideUp(400);
			$("#navi .sub").last().nextAll().animate( { top: "-=38px" }, 400 );
			$("#foot, #join, #joinMO").animate( { top: "-=48px" }, 400 );
			$(".pagecontent, .pchide").animate( { top: "-=38px" }, 400, function(){$(".pagecontent, .pchide").css({top:'320px'})});
			setTimeout ( function () {$("#navi .navidiv").fadeTo(0,0).each( function () {
				var _thisTop = $(this).prev().css('top');
				$(this).css('top',_thisTop);
			}); _thisElement.fadeTo(0, 0.5); }, 1400);
				
		}
		
		if ( $(mynewreadtext).hasClass("hide") ) {
			
			if ( $(this).is(".sub") ) {
				$("#navi .navidiv").fadeTo(0,0);
				if ($.browser.msie||$.browser.mozilla) {
					$("#navi .naviname li").css( { 'list-style-type':'none','margin-left':'11px'});
					$(this).prev().children().first().css( { 'list-style-type':'disc','margin-left':'11px'});
				} else {
					$("#navi .naviname li").css( { 'list-style-type':'none','margin-left':'11px'});
					$(this).prev().children().first().css( { 'list-style-type':'disc','margin-left':'0'});
				}
				var mytop='354px';
			} else {
				$("#navi .navidiv").fadeTo(0,0);
				_thisElement.fadeTo(0, 0.5);
				var mytop='320px';
			}			
			
			$(mynewreadtext).removeClass("hide");
			$(mynewreadview+">img:first").show();
			
			$("#cleanview").fadeIn(400);
			$(".pchide").fadeIn(400, function() {
			
				$(".pagecontent").addClass("hide").css({display:'none',top:mytop});
				$(mynewreadtext).removeClass("hide").css({display:'block'});
				$(".pchide").fadeOut(1200);
				
				$(".pagecontentright").css({display:'none'});
				$(mynewreadview).css({display:'block'});
				$("#cleanview").fadeOut(1200, function() {
					clearInterval ( myint );
					myint = setInterval( function() { slidenext(mynewreadview) }, 7000 );
					$("div[link]").remove();
					$("span[link]").each( function() {	
						var _thisH = $(this).height()+3;
						var _thisW = $(this).width();
						var _thisP = $(this).position();
						$('<div></div>').css ( {
							'background-image': 'url(__images/_bg.jpg)',
							'position': 'absolute',
							'left': _thisP.left+'px',
							'top': _thisP.top+'px',
							'width': _thisW+'px',
							'height': _thisH+'px',
							'cursor': 'pointer',
							'display': 'inline'
						} ).attr('link', $(this).attr('link') )
						.insertAfter(this).fadeTo(0,0);	
					});	
					$("div[link]").hover( function() {
						$(this).stop().fadeTo(400, 0.5);	
					}, function() {
						$(this).stop().fadeTo(200, 0);	
					});				
				});
			});
		}
	});
	
/* ******************************************************************************************************* */	
	$("#navi .top").click( function(){
		
		if ($("#navi .naviname").filter('.sub').is(":visible")) { 
			
			//$("#navi .sub").slideUp(400);
			//$("#navi .sub").last().nextAll().animate( { top: "-=34px" }, 400 );
			//$(".pagecontent").animate( { top: "-=34px" }, 400, function(){$(".pagecontent").css({top:'320px'})});
			//$("#navi .navidiv").fadeTo(0,0);
			
			
		} else {
		
			$("#navi .sub").slideDown(400);
			$("#navi .sub").last().nextAll().animate( { top: "+=38px" }, 400 );
			$(".pagecontent, .pchide").animate( { top: "+=38px" }, 400 );
			$("#foot, #join, #joinMO").animate( { top: "+=48px" }, 400 );
			$("#navi .naviname li").css( { 'list-style-type':'none','margin-left':'11px'});
			setTimeout( function() { $("#navi .navidiv:eq(3)").click(); $(".pagecontent, .pchide").css('top','358px'); }, 450 )
		}
		
	});
	
/* ******************************************************************************************************* */
	$("#hireview > .rightvars img").css('cursor','pointer').click(function(){  
		clearInterval ( myint );
		var mysrc = $(this).attr("src").slice(0,-5)+'.jpg'; 
		var myact = $("#hireview > img:visible"); 
		var mynext =  $("#hireview > img[src='"+mysrc+"']");
		if ( mynext.length == 0 ) mynext = $("#hireview > img:first");
		if ( myact.attr("src")!=mynext.attr("src") ){
			mynext.fadeIn(1800);
			myact.fadeOut(1800);
		}
		myint = setInterval( function() { slidenext("#hireview") }, 7000 );
	})
	.hover( function() {
		$(this).stop().fadeTo(400, 0.5);
	}, function() {
		$(this).stop().fadeTo(200, 1);	
	});
	
	
/* ******************************************************************************************************* */
	$("#locationview > .rightvars img").css('cursor','pointer').click(function(){  
		clearInterval ( myint );
		var mysrc = $(this).attr("src").slice(0,-5)+'.jpg'; 
		var myact = $("#locationview > img:visible"); 
		var mynext =  $("#locationview > img[src='"+mysrc+"']");
		if ( mynext.length == 0 ) mynext = $("#locationview > img:first");
		if ( myact.attr("src")!=mynext.attr("src") ){
			mynext.fadeIn(1800);
			myact.fadeOut(1800);
		}
		myint = setInterval( function() { slidenext("#locationview") }, 7000 );
	})
	.hover( function() {
		$(this).stop().fadeTo(400, 0.5);
	}, function() {
		$(this).stop().fadeTo(200, 1);	
	});
	
	/* ******************************************************************************************************* */
	$("#chouseview > .rightvars a[rel*='lightbox[ora]']").lightBox()
	$("#chouseview > .rightvars a[rel*='lightbox[ttc]']").lightBox()
	$("#chouseview > .leftvars a[rel*='lightbox']").lightBox()
	$("#chouseview > .rightvars img").css('cursor','pointer')
	.hover( function() {
		$(this).stop().fadeTo(400, 0.5);
	}, function() {
		$(this).stop().fadeTo(200, 1);	
	});

	$("#chouseview > .leftvars img").css('cursor','pointer')
	.hover( function() {
		$(this).stop().fadeTo(400, 0.5);
	}, function() {
		$(this).stop().fadeTo(200, 1);	
	});

/* ******************************************************************************************************* */
	$("#container img").css('cursor','pointer').click(function(){  
		clearInterval ( myint );
		var mysrc = $(this).attr("src").slice(0,-5)+'.jpg'; 
		var myact = $("#galleryview > img:visible"); 
		var mynext =  $("#galleryview > img[src='"+mysrc+"']");
		if ( mynext.length == 0 ) mynext = $("#galleryview > img:first");
		if ( myact.attr("src")!=mynext.attr("src") ){
			mynext.fadeIn(1800);
			myact.fadeOut(1800);
		}
		myint = setInterval( function() { slidenext("#galleryview") }, 7000 );
	})
	.hover( function() {
		$(this).stop().fadeTo(400, 0.5);
	}, function() {
		$(this).stop().fadeTo(200, 1);	
	});		

	 

/* ******************************************************************************************************* */	
	$("#galnext").hover(function(){  
		var _thisLeft = $("#container").css('left');
		if (_thisLeft == 'auto' || _thisLeft == '0px') _thisLeft=0; else _thisLeft= _thisLeft.slice(1,-2);
		var _newLeft = _galsize - 537;
		var _thisTime = (_newLeft - _thisLeft) * 10; 
		$("#container").animate( { left: "-"+_newLeft+"px" }, _thisTime );
	}, function(){
		$("#container").stop();
	});
	
	$("#galprev").hover(function(){  
		var _thisLeft = $("#container").css('left');
		if (_thisLeft == 'auto' || _thisLeft == '0px') _thisLeft=0; else _thisLeft= _thisLeft.slice(1,-2);
		var _thisTime = _thisLeft * 10; 
		$("#container").animate( { left:"0px" }, _thisTime );
	}, function(){
		$("#container").stop();
	});

/* ******************************************************************************************************* */
	
	$("span[link]")
	//.prepend('<img src="__images/_click.gif" />')
	.each( function() {	
		var _thisH = $(this).height()+3;
		var _thisW = $(this).width();
		var _thisP = $(this).position();
		$('<div></div>').css ( {
			'background-image': 'url(__images/_bg.jpg)',
			'position': 'absolute',
			'left': _thisP.left+'px',
			'top': _thisP.top+'px',
			'width': _thisW+'px',
			'height': _thisH+'px',
			'cursor': 'pointer',
			'display': 'inline'
		} ).attr('link', $(this).attr('link') )
		.insertAfter(this).fadeTo(50,0);	
	});
		
	
	$("div[link]").hover( function() {
		$(this).stop().fadeTo(400, 0.5);	
	}, function() {
		$(this).stop().fadeTo(200, 0);	
	});	
	
	
	$("div[link]").live('click', function() {
		var _thisLink = $(this).attr('link');
		switch (_thisLink) {
			
			case 'address':
				window.open( 'http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=The+Pantechnicon,+10+Motcomb+Street,+London,+SW1X+8LA&aq=&sll=51.49968,-0.15651&sspn=0.00748,0.015857&g=10+Motcomb+St,+London+SW1X+8LA,+United+Kingdom&ie=UTF8&hq=The+Pantechnicon,&hnear=10+Motcomb+St,+London+SW1X+8LA,+United+Kingdom&ll=51.49954,-0.156426&spn=0.00748,0.015857&z=16');
				break;
				
			case 'makeres':
				window.open( 'http://uk.opentable.com/the-pantechnicon-public-house-and-dining-rooms-reservations-london?rid=31483&restref=31483' );
				break;
					
			case 'hire':
				window.open( 'http://www.cubitthouse.co.uk/pdfs/cubitthouse-functions.pdf' );
				break;
					
			case 'bannermsg':
				window.open('http://www.cubitthouse.co.uk/?special');
				break;
					
			case 'lrfmenu':
				window.open('__pdf/TPR_LONDON_FESTIVAL.pdf');
				break;
					
			case 'pubfood':
				window.open( '__pdf/TPR_BAR_FRONT.pdf' );
				break;	
					
			case 'bar':
				window.open( '__pdf/TPR_BAR_FRONT.pdf' );
				break;
					
			case 'lunch':
				window.open( '__pdf/TPR_SET_LUNCH_MENU.pdf' );
				break;
					
			case 'set':
				window.open( '__pdf/TPR_SET_LUNCH_MENU.pdf' );
				break;
					
			case 'weekend':
				window.open( '__pdf/TPR_BREAKFAST_MENU.pdf' );
				break;
					
			case 'breakfast':
				window.open( '__pdf/TPR_BREAKFAST_MENU.pdf' );
				break;
					
			case 'dining':
				window.open( '__pdf/TPR_DINING_ROOM_MENU.pdf' );
				break;
					
			case 'wine':
				window.open( '__pdf/TPR_WINE_LIST.pdf' );
				break;
					
			case 'function-set':
				window.open( '__pdf/TPR_SET_MENUS.pdf' );
				break;
					
			case 'xmas-set':
				window.open( '__pdf/TPR_CHRISTMAS_FUNCTION_SET_MENU.pdf' );
				break;
					
			case 'p-res':
				window.location.href = 'mailto:reservations@thepantechnicon.com';
				break;
					
			case 'm-saskia':
				window.location.href = 'mailto:saskia@cubitthouse.co.uk';
				break;
					
			case 'r-ora':
				window.location.href = 'mailto:reservations@theorange.co.uk';
				break;
					
			case 'l-ora':
				window.open( 'http://www.theorange.co.uk/');
				break;
					
			case 'r-tgg':
				window.location.href = 'mailto:reservations@thegrazinggoat.co.uk';
				break;
					
			case 'l-tgg':
				window.open( 'http://www.thegrazinggoat.co.uk/');
				break;
					
			case 'r-ch':
				window.location.href = 'mailto:reservations@thethomascubitt.co.uk';
				break;
					
			case 'l-ch':
				window.open('http://www.thethomascubitt.co.uk/');
				break;
					
			case 'l-join':
				window.open('http://www.cubitthouse.co.uk/?view=work');
				break;
			
			case 'l-tgg':
				window.open('http://www.thegrazinggoat.co.uk/');
				break;
			
			case 'l-cubitthouse':
				window.open('http://www.cubitthouse.co.uk/');
				break;
			
			case 'l-festival':
				window.open('http://www.visitlondon.com/londonrestaurantfestival/');
				break;
			
			
			default:
		}
				
	});
		
		
});


