var $j = jQuery.noConflict();

var urlParams = {};
(function () {
    var e,
        a = /\+/g,  // Regex for replacing addition symbol with a space
        r = /([^&;=]+)=?([^&;]*)/g,
        d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
        q = window.location.search.substring(1);

    while (e = r.exec(q))
       urlParams[d(e[1])] = d(e[2]);
})();


/* function loaded() {	
if( !$j.browser.msie ) {
	if ($j(".iscroll").length) { 
		$j('.iscroll').bind( 'touchmove', function(e){ e.preventDefault(); })
	myScroll = new iScroll('newssleeve', { checkDOMChanges: false} );
		}
}
} */

$j.html5vids = ( (!$j.browser.msie && document.createElement( 'video' ).canPlayType( 'video/mp4' ) != '') || Android === 1 ) ? true : false;

function videoSwap(selecta) {
		$j( selecta ).each( function()
		{
			id = $j( this ).attr( 'id' ) + '-flash';
			w = $j( this ).attr( 'width' );
			h = $j( this ).attr( 'height' );
			c = $j( this ).attr( 'class' );

			flashvars =
			{
				file: $j( this ).attr( 'src' ),
				id: id,
				controlbar: 'none',
				width: w,
				height: h,
				volume: '90',
				mute: false,
				screencolor: 'eeeeee'
			};
				
			if( $j( this ).attr( 'controls' ) && $j( this ).hasClass('ipadplay') != true )
				flashvars.controlbar = 'none';
			
			if( $j( this ).attr( 'autoplay' ) )
				flashvars.autostart = 'true';
				
			if( $j( this ).attr( 'poster' ) )
				flashvars.image = $j( this ).attr( 'poster' );
			
			params =
			{
				allowscriptaccess: 'always',
				allowfullscreen: 'true',
				wmode: 'transparent'
			};
			
			attributes =
			{
				id: id,
				name: id,
				styleclass: c
			};	
			
			
			
			swfobject.embedSWF( BD + '/scripts/player.swf', $j( this ).attr( 'id' ), w, h, '9', BD + '/scripts/express-install-flash.swf', flashvars, params, attributes );
		});
		
	}

	
	
var player;
function playerReady( obj ){ player = document.getElementById( obj['id'] ); }


var nameinput = document.getElementById ('author');
var emailinput = document.getElementById ('email');
var urlinput = document.getElementById ('url');
var commentinput = document.getElementById ('comment');
function formclear() {
	if ( nameinput.value == 'Name*' || nameinput.value == 'Name') nameinput.value='';
	if ( emailinput.value == 'Email Address*' || emailinput.value == 'Email Address') emailinput.value='';
	if ( urlinput.value == 'Website') urlinput.value='';
}

function inArray(needle, haystack) {
    var length = haystack.length;
    for(var i = 0; i < length; i++) {
        if(haystack[i] == needle) return true;
    }
    return false;
}

function pushtocookie(eventname, cookiename, cookielist) {
	if (typeof eventname != 'undefined') {
cookielist.push(eventname);
$j.cookie(cookiename, cookielist, {  expires: 30, path: '/'});
	}
}
	
$j(document).ready(function(){

	$j("#gridthumbs a").fancybox({
				'titleShow'     : true,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic' /* ,
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>'; 
				} */
			});

	/* $j('#slider').nivoSlider({
	pauseTime:5000,
	directionNav:false
	}); */


/* Cookie Clearing Query String. Append URL with ?clear=cookies to initiate */

if (urlParams['clear'] == 'cookies') { 
		$j.cookie('jcookielist', null, { path: '/'});
}


/* Gets current list of fired events and stores them as flags to see whether to fire animations or not */

var currentcookies = $j.cookie('jcookielist');
var jcookies = currentcookies ? currentcookies.split(/,/) : new Array();

if ( typeof wppage != 'undefined') {
	var slidefired = 'slidefired-' + wppage;
	var firecheck = inArray(slidefired,jcookies)
}
else {
	var slidefired = null;
	var firecheck = false;
}




/* Slide in animation */

if ( $j('.slidein').length) {
	if (firecheck == false) { 
	$j('.slidein').animate({left: '0px' },  { duration: 2000, easing: 'easeOutBounce'});
	if ( $j('.zero').length) {
		$j('.zero img').delay(2000).animate({'opacity': 1}, 1500);
		$j('.zero .doone').delay(2000).animate({'opacity': 0}, 1500);
	}

	// if (!$j.browser.msie) { $j('#rightbox').animate({'opacity': 1}, 2000); } 
	pushtocookie(slidefired,'jcookielist',jcookies);
	}
	
	
	else { 
	$j('.slidein').css({left: '0px'});  
	$j('.zero img').css({'opacity': 1});
	$j('.doone').css({'opacity': 0});
	// if (!$j.browser.msie) { $j('#rightbox').css({'opacity': 1}); }
	
	}
}

else {
if (!$j.browser.msie) { 
	// $j('#rightbox').css({'opacity': 1}); 
	}
}


	
	
	// Begin jQuery video loading scripts
	// This detects HTML 5

	if( !$j.html5vids )
	{
	videoSwap('video');
	}
	

	// End video initalisation script
	
			
	$j('#navcontain #topnav li:nth-child(1)').addClass('menu-no-1');
	$j('#navcontain #topnav li:nth-child(2)').addClass('menu-no-2');
	$j('#navcontain #topnav li:nth-child(3)').addClass('menu-no-3');
	$j('#navcontain #topnav li:nth-child(4)').addClass('menu-no-4');
	$j('#navcontain #topnav li:nth-child(5)').addClass('menu-no-5');
	$j('#navcontain #topnav li:nth-child(6)').addClass('menu-no-6');
	$j('#navcontain #topnav li:nth-child(7)').addClass('menu-no-7');
	
		
	var vidProps =
	{
		width: 332,
		height: 192,
		defaultVid: BD + '/img/video-intro.gif'
	};

if ( $j('#threesixty').length) {	
	var flashvars = {};
	var params =
	{
		allowscriptaccess: 'always',
		allowfullscreen: 'true',
		wmode: 'transparent'
	};
	var attributes1 =
	{
		width: '520',
		height: '355',
		name: '360-third-floor',
		id: '360-third-floor'
	};
	var attributes2 =
	{
		width: '520',
		height: '355',
		name: '360-fifth-floor',
		id: '360-fifth-floor'
	};
	swfobject.embedSWF( BD + '/img/3rd_floor_0360_out.swf', 'placethird-floor', '520', '355', '9', BD + '/scripts/express-install.swf', flashvars, params, attributes1 );
	swfobject.embedSWF( BD + '/img/5th_Floor_0360_out.swf', 'placefifth-floor', '520', '355', '9', BD + '/scripts/express-install.swf', flashvars, params, attributes2 );		
	
}
	
  	if( !$j.browser.msie && document.createElement( 'video' ).canPlayType( 'video/mp4' ) && $j( '.homenewsstory.flv' ).length == 0 )
	{	
		$j( 'html' ).addClass( 'html5vids' );
		$vid = $j( '<video />' )
		.bind( 'canplay', function(){ this.play() } )
		.attr
		({
			id: 'newsVidHtml5',
			width: vidProps.width,
			height: vidProps.height,
			controls: 'none',
			poster: BD + '/img/video-intro.gif'
		})
		
		
		$j( '#playerCon' ).css({ height: '192px' });

		$j( '#placePlayer' ).replaceWith( $vid );
	}
	else
	{
		flashvars =
		{
			file: vidProps.defaultVid,
			id: 'newsVidFlash',
			autostart: 'true',
			controlbar: 'none'
		};
		attributes =
		{
			id: 'newsVidFlash',
			name: 'newsVidFlash'
		};
		
		swfobject.embedSWF( BD + '/scripts/player.swf', 'placePlayer', vidProps.width, vidProps.height, '9', BD + '/scripts/express-install.swf', flashvars, params, attributes );
	}
		
if( Android === 1) {
	
	$j( '.blogPlayer' ).each( function(index) {
		v[index] = $j(this).attr('id');
		v[index].addEventListener('click',function(){
  		v[index].play();
		},false);
	});
}

$j('.slideshow').cycle(); 


$j('#mybook').booklet({
	        closed: true,
			 width:  494,
	        height: 320,
			pagePadding: 0,
			pageNumbers: false
	    });	


$j("#floornav #fifth, .sizes #floorfive").click(function() {
var image = $j('#floornav #fifth a').attr("href");
var alt = $j('.sizes #floorfive .redlarge').html();
$j('.floorplan').hide();
$j('.floorplan').fadeIn('slow');
$j('.floorplan').html('<img src="' + image + '" alt="' + alt + '" />');
$j('#floornav a, .sizes tr').removeClass('active');
$j('#floornav #fifth a, .sizes #floorfive').addClass("active");
return false;
 });
$j("#floornav #fourth, .sizes #floorfour").click(function() {
var image = $j('#floornav #fourth a').attr("href");
var alt = $j('.sizes #floorfour .redlarge').html();
$j('.floorplan').hide();
$j('.floorplan').fadeIn('slow');
$j('.floorplan').html('<img src="' + image + '" alt="' + alt + '" />');
$j('#floornav a, .sizes tr').removeClass('active');
$j('#floornav #fourth a, .sizes #floorfour').addClass("active");
return false;
 });
$j("#floornav #third, .sizes #floorthree").click(function() {
var image = $j('#floornav #third a').attr("href");
var alt = $j('.sizes #floorthree .redlarge').html();
$j('.floorplan').hide();
$j('.floorplan').fadeIn('slow');
$j('.floorplan').html('<img src="' + image + '" alt="' + alt + '" />');
$j('#floornav a, .sizes tr').removeClass('active');
$j('#floornav #third a, .sizes #floorthree').addClass("active");
return false;
 });
$j("#floornav #second, .sizes #floortwo").click(function() {
var image = $j('#floornav #second a').attr("href");
var alt = $j('.sizes #floortwo .redlarge').html();
$j('.floorplan').hide();
$j('.floorplan').fadeIn('slow');
$j('.floorplan').html('<img src="' + image + '" alt="' + alt + '" />');
$j('#floornav a, .sizes tr').removeClass('active');
$j('#floornav #second a, .sizes #floortwo').addClass("active");
return false;
 });
$j("#floornav #first, .sizes #floorone").click(function() {
var image = $j('#floornav #first a').attr("href");
var alt = $j('.sizes #floorone .redlarge').html();
$j('.floorplan').hide();
$j('.floorplan').fadeIn('slow');
$j('.floorplan').html('<img src="' + image + '" alt="' + alt + '" />');
$j('#floornav a, .sizes tr').removeClass('active');
$j('#floornav #first a, .sizes #floorone').addClass("active");
return false;
 });
$j("#floornav #reception, .sizes #floorreception").click(function() {
var image = $j('#floornav #reception a').attr("href");
var alt = $j('.sizes #floorreception .redlarge').html();
$j('.floorplan').hide();
$j('.floorplan').fadeIn('slow');
$j('.floorplan').html('<img src="' + image + '" alt="' + alt + '" />');
$j('#floornav a, .sizes tr').removeClass('active');
$j('#floornav #reception a, .sizes #floorreception').addClass("active");
return false;
 });
 
$j('.thirdfloor360 a').click(function(){
	$j('.fifthfloor360 a').removeClass('active');
	$j('.thirdfloor360 a').addClass('active');
 	$j('.threesixtycontent .sleeve').animate({ 'top':'0px' }, 1500);
	return false;
});

$j('.fifthfloor360 a').click(function(){
	$j('.thirdfloor360 a').removeClass('active');
	$j('.fifthfloor360 a').addClass('active');
 	$j('.threesixtycontent .sleeve').animate({ 'top':'-355px' }, 1500);
	return false;
});




if ($j('.switcha').length ) {
	$j('.slidein').css({paddingTop: '265px', height: '215px'});	
}



}); 
/*
if( !$j.browser.msie ) {
document.addEventListener('DOMContentLoaded', loaded);
}*/


