﻿/* Stickyworld gallery.js modified for WP from PHPFrame*/

var timers = new Array();
var targets = new Array();
var expand_interval = null;
var contract_interval = null;
var footer_height = 145;
var restore_timer = null;
var minimize_timer = null;

function filter_directory() {
	
}

function timeRestore() {
	stopMinimize();
	var expanded = jQuery('#floating-gallery').hasClass('expanded');
	var minimized = jQuery('#floating-gallery').hasClass('minimize');
	if (minimized && !expanded && restore_timer == null) restore_timer = setTimeout("restore()", 600);
}

function restore() {
	if (minimize_timer != null) clearTimeout(minimize_timer);
	if (restore_timer != null) clearTimeout(restore_timer);
	minimize_timer = null;
	restore_timer = null;
	jQuery('#floating-gallery').removeClass('minimize');
}

function toggleMinimize() {
	jQuery('#floating-gallery').toggleClass('minimize');
}

function timeMinimize() {
	stopRestore();
	var expanded = jQuery('#floating-gallery').hasClass('expanded');
	var minimized = jQuery('#floating-gallery').hasClass('minimize');
	if (!minimized && minimize_timer == null) minimize_timer = setTimeout("minimize()",600);
}

function minimize() {
	if (restore_timer != null) clearTimeout(restore_timer);
	if (minimize_timer != null) clearTimeout(minimize_timer);
	restore_timer = null;
	minimize_timer = null;
	jQuery('#floating-gallery').addClass('minimize');
}

function stopMinimize() {
	if (minimize_timer != null) clearTimeout(minimize_timer);
	minimize_timer = null;
}

function stopRestore() {
	if (restore_timer != null) clearTimeout(restore_timer);
	restore_timer = null;
}

function stopMinRes() {
	stopMinimize();
	stopRestore();
}

//FLOAT PANE AND FOOTER STUFF
function showFooter(tab_name) {
	//is active?
	if(jQuery('#fttab_'+tab_name).hasClass('current-ft'))
	{
		//yes:
		toggle_expand_footer();
	} else {
		//no:
		jQuery('.ft-tab').removeClass('current-ft');
		jQuery('.ft-pane').hide();
		jQuery('#ftpane_'+tab_name).show()
		jQuery('#fttab_'+tab_name).addClass('current-ft');
		check_scroll(tab_name);
	}
}

function toggle_expand_footer() {
	//clever stuff
	jQuery('#floating-gallery').toggleClass('expanded');
	if(jQuery('#floating-gallery').hasClass('expanded')) {
		//expand
		start_expand();
		jQuery('#floating-gallery .rooms').css('left','0px');
		//jQuery('#menu-hider').slideDown('slow');
		jQuery('body').css('overflow','hidden');
		scroll(0,0);
	} else {
		//contract
		minimize();
		start_contract();
		jQuery('#menu-hider').hide();
		check_scroll('ShowRooms');
		jQuery('body').css('overflow','scroll');
	}
}

function start_expand() {
	clearInterval(expand_interval);
	clearInterval(contract_interval);
	var float_pane = jQuery('#floating-gallery');
	float_pane.css('top', parseInt(float_pane.offset().top)+'px');
	float_pane.css('height','100%');
	expand_interval = window.setInterval('footer_expand()',20);
	//window.setTimeout(function () {clearInterval(expand_interval);},3500);				
}

function footer_expand() {
	var float_pane = jQuery('#floating-gallery');
	var current_top = float_pane.offset().top;
	var expand_transition = (current_top - 90)/8;
	if(expand_transition > 40) expand_transition = 40;
	new_top = parseInt(current_top - expand_transition); 
	if (new_top <= 95) {
		new_top = 90;
		clearInterval(expand_interval);
	}
	float_pane.css('top', new_top);
}

function start_contract() {
	clearInterval(expand_interval);
	clearInterval(contract_interval);
	var float_pane_elm = document.getElementById('floating-gallery');
	var current_height = float_pane_elm.offsetHeight - footer_height;
	var float_pane = jQuery('#floating-gallery');
	float_pane.css('height',current_height);
	float_pane.css('top',null);
	contract_interval = window.setInterval('footer_contract()',20);
	//window.setTimeout(function () {clearInterval(contract_interval);},3500);				
}

function footer_contract() {			
	var float_pane = document.getElementById('floating-gallery');
	var current_height = float_pane.offsetHeight;
	var contract_transition = (current_height - footer_height)/8;
	if(contract_transition > 40) contract_transition = 40;
	new_height = parseInt(current_height - contract_transition); 
	if (contract_transition <= 2) {
		float_pane.style.height = footer_height+'px';
		clearInterval(contract_interval);
		jQuery('body').css('overflow','scroll');
	} else {
		float_pane.style.height = new_height+'px';
	}
}
//FLOAT PANE AND FOOTER STUFF

//used to start off scrolling of slides left or right
function g_scroll(pane_id,distance,chunk,trigger)
{
	
	if(trigger.className == 'inactive') return false;

	//get the div inside the pane which contains the slides 
	slides=document.getElementById(pane_id+'_slides');
	//get int value of slides div left offset
	left = slides.style.left;
	if (left == '')	left=0
	else left = parseInt(left);
	//get the width of the slides div
	width = slides.style.width.replace('px','');
	if (width == '') width = 0
	else width = parseInt(width);
	
	if(chunk)
	{
		//get the sroller (visible part of slides) and its width
		scroller=document.getElementById(pane_id+'_scroller');
		width=scroller.offsetWidth;
		//find amount of slides visible
		slides_visible = Math.abs(parseInt(width / distance));
		//set new distance
		distance *= slides_visible;
	}
	
	//the actual scrolling
	if (targets[pane_id] != undefined)
	{
		//already scrolling, adjust target
		targets[pane_id] = targets[pane_id] + distance;
	}
	else
	{
		//set target
		targets[pane_id] = left + distance;
		//start ticker for smooth scrolling animation
		timers[pane_id] = setInterval('scrolling(\'' + pane_id + '\');',25);	//start a timer interval
	}
	
	check_scroll(pane_id);
}

//scrolls slides smoothly
function scrolling(pane_id)
{
	//get the div inside the pane which contains the slides 
	slides=document.getElementById(pane_id+'_slides');
	//get int value of slides div left offset
	left = slides.style.left;
	if (left == '')	left=0
	else left = parseInt(left);
	
	adjustment = (targets[pane_id] - left)/4;
	if (adjustment > 0 && adjustment < 2 || adjustment < 0 && adjustment > -2) 
	{
		end_scroll(pane_id);
		return;
	}
	left += adjustment;
	slides.style.left = left + 'px';
}

function end_scroll(pane_id)
{
	//get the div inside the pane which contains the slides 
	slides=document.getElementById(pane_id+'_slides');
	//get int value of slides div left offset
	left = slides.style.left;
	if (left == '')	left=0
	else left = parseInt(left);
	
	slides.style.left = targets[pane_id] + 'px';
	check_scroll(pane_id);
	
	delete targets[pane_id];
	clearInterval(timers[pane_id]);
}

//toggles the overlay info on work and people
function overlay_toggle(div_id, toggle)
{	
	//get the slide we are overlaying
	div=document.getElementById(div_id);
	//get the overlay
	overlay=document.getElementById(div_id+'_overlay');
	if (toggle=='on')
	{
		//make the slide invisible and the overlay visible
//		div.style.display='none';
		overlay.style.display='inline';
	}
	else
	{
		//make overlay invisible and the slide visible
		overlay.style.display='none';
//		div.style.display='block';
	}
}

//used to enable/disable scroll buttons on panes as necessary
function check_scroll(pane_id)
{
	//get the sroller (visible part of slides) and its width
	var scroller=document.getElementById(pane_id+'_scroller');
	if (scroller == null) return false;
	width = scroller.offsetWidth;
	//get the slides and their width
	slides=document.getElementById(pane_id+'_slides');
	slides_width=slides.offsetWidth;
	//get the arrows
	r_arr=document.getElementById(pane_id+'_r-arr').firstChild;
	l_arr=document.getElementById(pane_id+'_l-arr').firstChild;
	
	//if the slides are bigger than the scroller, we can scroll
	if(width < slides_width)
	{
		if (targets[pane_id] != undefined)
		{
			//if the pane has a target, use it instead of the left
			left = targets[pane_id];
		}
		else
		{	
			//else get the left offset of the slides
			left=slides.style.left.replace('px','');
			if (left == '')	left=0
			else left = parseInt(left);
		}
		
		//if left is bigger than 0 we can't scroll left, else.. we can
		if(left>=0) { 
			l_arr.className = 'inactive';
		} else {
			l_arr.className = 'active';
		}
		
		//if the right-hand side of the slides is inside the scroller, we can't scroll right
		if(slides_width+left<=width+5) r_arr.className = 'inactive' //r_arr.style.display='none'
		else r_arr.className = 'active'; //r_arr.style.display='block';
	}
	else
	{
		//we can't scroll, make sure slides are on left=0 and disable arrows
		slides.style.left='0px';
		//r_arr.style.display='none';
		r_arr.className = 'inactive';
		//l_arr.style.display='none';
		l_arr.className = 'inactive';
	}
}

function load_vid(link_code, autoplay)
{
	if(autoplay==null)autoplay = true;
	link_code="/"+link_code;
	link_code=link_code.replace("watch?","");
	link_code=link_code.replace("=","/");
	var auto_param = "&autoplay=0";
	if(autoplay) auto_param = "&autoplay=1";
	embed_code = '<object width="598" height="474"><param name="movie" value="http://www.youtube.com'+link_code+'&hl=en_GB&fs=1'+auto_param+'&rel=0&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><param name="wmode" value="transparent"><embed src="http://www.youtube.com'+link_code+'&hl=en_GB&fs=1'+auto_param+'&rel=0&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="598" height="474" wmode="transparent"></embed></object>';

	jQuery('#demovideo').html(embed_code);
}

function set_trust_fixed_width(show_id)
{
	var show_width = 0;
	var show_elements = jQuery('#'+show_id+' .slides').children();
	jQuery('#'+show_id+' .slides').children().each(function(i){

		element_width = show_elements[i].offsetWidth;
		element_margin = parseInt(jQuery(this).css('margin-right').replace('px',''));
		if(element_width - element_margin <= 0) {
			setTimeout('set_trust_fixed_width("'+show_id+'");',1000);
			return false
		}
		show_width += element_width + element_margin;
	});
	
	var show_slides = jQuery('#'+show_id+' .slides');
	show_slides.width(show_width);
}