
// 'stacks' is the Stacks global object.
// All of the other Stacks related Javascript will 
// be attatched to it.
var stacks = {};


// this call to jQuery gives us access to the globaal
// jQuery object. 
// 'noConflict' removes the '$' variable.
// 'true' removes the 'jQuery' variable.
// removing these globals reduces conflicts with other 
// jQuery versions that might be running on this page.
stacks.jQuery = jQuery.noConflict(true);

// Javascript for stacks_in_11_page19
// ---------------------------------------------------------------------

// Each stack has its own object with its own namespace.  The name of
// that object is the same as the stack's id.
stacks.stacks_in_11_page19 = {};

// A closure is defined and assigned to the stack's object.  The object
// is also passed in as 'stack' which gives you a shorthand for referring
// to this object from elsewhere.
stacks.stacks_in_11_page19 = (function(stack) {

	// When jQuery is used it will be available as $ and jQuery but only
	// inside the closure.
	var jQuery = stacks.jQuery;
	var $ = jQuery;
	
// TopBox is designed and developed by Will Woodgate

var $tb = jQuery.noConflict();
$tb(document).ready(function(){

	
// Append TopBox and window shade onto the page body tag
$tb('#topBoxContentstacks_in_11_page19').css({display: 'block'});
$tb('body').append('<div id="topBoxstacks_in_11_page19" class="topBox"></div><div id="shadestacks_in_11_page19"></div>');


// Move Stack content up into the TopBox and block display the hidden content
$tb('#topBoxContentstacks_in_11_page19').appendTo('#topBoxstacks_in_11_page19');

// Trigger TopBox when user clicks on a link with matching REL tag and prevent anchor jump
$tb('[class=topbox1]').click(function (e) {
		e.preventDefault();

// Fetches the screen height and width to calculate shade size
var shadeHeight = $tb(document).height();  
var shadeWidth = $tb(window).width();

// Centers the TopBox horizontally, based on screen size
var topboxHori = $tb('#topBoxstacks_in_11_page19');
topboxHori.css({left: '50%','margin-left': 0 - (topboxHori.width() / 2)
});

// Centers the TopBox vertically, based on screen size
var topboxVert = $tb('#topBoxstacks_in_11_page19');
topboxVert.css({top: '50%','margin-top': 0 - (topboxVert.height() / 2)
});
      
//Set height and width of shade to fill up the whole screen
$tb('#shadestacks_in_11_page19').css({'width':shadeWidth,'height':shadeHeight,'opacity':.85});

// Fade in window shade and TopBox on click and set fade speed
$tb('#shadestacks_in_11_page19, #topBoxstacks_in_11_page19').fadeIn(800);

// If the iFrame module is enabled, append generated iFrame to the iFrame container. Otherwise this line is commented out
//$tb('#iframeModulestacks_in_11_page19').append('<iframe id="generatediFramestacks_in_11_page19" src="http://www.bbc.co.uk/">Your web browser does not support iframes.</iframe>');

});


// Fade out window shade, TopBox by clicking on window shade  
$tb('#shadestacks_in_11_page19').click(function(){
$tb('#shadestacks_in_11_page19, #topBoxstacks_in_11_page19').fadeOut(800);
// If enabled, terminate the iFrame module also. Otherwise this line is commented out
//$tb('#generatediFramestacks_in_11_page19').remove();
})

// Fade out window shade and TopBox by clicking on a backwards link  
$tb('#topBoxstacks_in_11_page19 a').click(function(){
$tb('#shadestacks_in_11_page19, #topBoxstacks_in_11_page19').fadeOut(800);
// If enabled, terminate the iFrame module also. Otherwise this line is commented out
//$tb('#generatediFramestacks_in_11_page19').remove();
})

// Fade out window shade and TopBox by clicking on a forwards link  
$tb('#topBoxForwardsstacks_in_11_page19').click(function(){
$tb('#shadestacks_in_11_page19, #topBoxstacks_in_11_page19').fadeOut(800);
// If enabled, terminate the iFrame module also. Otherwise this line is commented out
//$tb('#generatediFramestacks_in_11_page19').remove();
})

// Fade out window shade and TopBox by clicking on close button  
$tb('.topBoxClose').click(function(){
$tb('#shadestacks_in_11_page19, #topBoxstacks_in_11_page19').fadeOut(800);
// If enabled, terminate the iFrame module also. Otherwise this line is commented out
//$tb('#generatediFramestacks_in_11_page19').remove();
})

// Fade out window shade and TopBox using keyboard ESC key
$tb(document).keydown( function( e ) { 
   if( e.which == 27) {
     $tb('#shadestacks_in_11_page19, #topBoxstacks_in_11_page19').fadeOut(800);
     // If enabled, terminate the iFrame module also. Otherwise this line is commented out
     //$tb('#generatediFramestacks_in_11_page19').remove();
   } 
 }); 
 
 // If an iOS device is detected, change TopBox position to absolute and scroll page to the top. 
 var deviceAgent = navigator.userAgent.toLowerCase();
 	var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
 	if (agentID) {
 	$tb('[class=topbox1]').each(function() { 
 		$tb('#topBoxstacks_in_11_page19').css({position: 'absolute'});
 		$tb(this).click(function() { 
 			setTimeout(scrollTo, 0, 0, 1); 
 			}); 
 		}); 
 	}

});

// Recalculate the window shade size when the window is resized.
$tb(window).resize(function() {

	//Fetches the screen height and width to calculate shade size
	var shadeHeight = $tb(document).height();  
	var shadeWidth = $tb(window).width();

    $tb('#shadestacks_in_11_page19').css({'width':shadeWidth,'height':shadeHeight,'opacity':.85});
});











	








/*

var $tb = jQuery.noConflict();
$tb(document).ready(function(){

//Scroll page up on iOS to bring TopBox into view
if((navigator.userAgent.match(/iPhone/i))||(navigator.userAgent.match(/iPad/i))) { 
$tb('[rel=basicstyledtext]').each(function() { 
	$tb(this).click(function() { 
		setTimeout(scrollTo, 0, 0, 1); 
		}); 
	}); 
}

*/
	return stack;
})(stacks.stacks_in_11_page19);



