function panochange (newPano) {
	//alert(newPano);
	for (var Current=0;Current < document.selform.select2.options.length;Current++) {
		if (document.selform.select2.options[Current].value == newPano) {
		 document.selform.select2.selectedIndex = newPano;
		 //alert (Current);
		}
	}
	document.selform.select2.selectedIndex=newPano;
	formHandler(newPano);
}

function loadTour (i) {
	document.ptviewer.newPanoFromList(parseInt(i));
	document.ptviewer.showHS();
	return false;
}

$.fn.placeholder = function (options) {
    if (this[0] && 'placeholder' in document.createElement('input')) {
		return;
    }
    $.fn.placeholder.defaults = {
        focusClass: 'focus'
    };
    var settings = $.extend({},
    $.fn.placeholder.defaults, options);
    return this.each(function (i, e) {
        var el = $(e),
        val = el.attr('placeholder');
        el.val(val);
        el.bind('focus',
        function () {
            if (el.val() === val) {
                el.addClass(settings.focusClass).val('');
            }
        }).bind('blur',
        function () {
            if (el.val() === '') {
                el.removeClass(settings.focusClass).val(val);
            }
        });
    });
};


$(function () {

	//form validation
	
	$('#bookingform').submit(function(){
		return CheckForm(this.id);
	});

	//tagline rotator

	var tagline = $('#tagline'),
	taglineVals = [
		'Round-the-clock CCTV and on-site security',
		'24-hour access',
		'Disability Discrimination Act (DDA) compliant',
		'BREEAM "Very Good" rating',
		'Allocated on-site parking with visitor spaces',
		'.Adjacent to Longbridge railway station',
		'Less than 3 miles from the M5 J4 and M42 J2'
	],
	taglineValsLength = taglineVals.length,
	i = 0,
	rotateTagline = function () {
		i = (i === taglineValsLength) ? 0 : i;
		tagline.html('&hellip;' + taglineVals[i] + '&hellip;');
		i++;
	};
	
	setInterval(function () {
		rotateTagline();
	}, 3000);
	
	$('.expander .more a').click(function (event) {
		$('.expander').height('auto');
		$('.toggle').slideDown();
		$('.expander .more').hide();
		event.preventDefault();
	});
	
	//autocomplete
	$('#cntnt01searchinput').autocomplete({
		source: 'autocomplete-json.php'
	});

	//var $dropdownLinks = $('.business-nav a:not(li li a), .innovation-centre-nav a:not(li li a)');

	$('.business-nav, .innovation-centre-nav').hover(function () {
		$('#applet').hide();
		$(this).children('ul').fadeIn();
		$(this).find('a:eq(0)').addClass('hover');
	}, function () {
		$('#applet').show();
		$(this).children('ul').hide();
		$(this).find('a:eq(0)').removeClass('hover');
	});

	//gallery
	var status = 'pause';
	
	$('#cntnt01searchinput').attr('placeholder', 'Search').placeholder();
	
	$('.the-vision a').colorbox({
		iframe: true,
		innerWidth:640,
		innerHeight:480
	});
	$('.webcam a').colorbox({
		iframe: true,
		width: '95%',
		height: '95%'
	});
	$('.thickbox').colorbox();

	$('.gallery-images p').cycle({
		next: '#next',
		prev: '#prev',
		timeout: 6000
	});
	
	$('#next, #prev').click(function () {
		$('.gallery-images p').cycle('resume');
		status = 'pause';
		$('#pause img').attr('src', '/css/images/pause.png');
	});
	
	$('#pause').click(function (event) {
		$('.gallery-images p').cycle(status);
		var img = $(this).children('img');
		if (status === 'pause') {
			status = 'resume';
			img.attr('src', '/css/images/play.png');
		} else {
			status = 'pause';
			img.attr('src', '/css/images/pause.png');
		}
		event.preventDefault();
	});

	//Category Chooser
	$('#choose-category').change(function () {
		var newsClass = $(this).val();
		$('.latest-news div').hide();
		$('.' + newsClass).show();
	});

	//grand plan map
	$('#grand-plan-map li').hover(function () {
		$('#grand-plan-map li').css({zIndex: 100}).children().hide();
		var i = '#map-nav li:eq(' + $(this).index() + ') a';
		$('#map-nav li a').removeClass('hover');
		$(i).addClass('hover');
		$(this).css({zIndex: 1000}).children('div').show();
	},function(){
		var i = '#map-nav li:eq(' + $(this).index() + ') a';
		$(i).removeClass('hover');
		$(this).css({zIndex: 100}).children('div').hide();
	});
	$('#map-nav li').click(function (event) {
		var i = '#grand-plan-map li:eq(' + $(this).index() + ')';
		$('#map-nav li a').removeClass('hover').eq($(this).index()).addClass('hover');
		$('#grand-plan-map li').css({zIndex: 100}).children('div').hide();
		$(i).css({zIndex: 1000}).children().show();
		event.stopPropagation();
		event.preventDefault();
	});
	$('body').click(function () {
		$('#map-nav li a').removeClass('hover');
		$('#grand-plan-map li').css({zIndex: 100}).children('div').hide();
	});

	//external links
	$('a[rel="external"]').click(function () {
		window.open(this.href);
		return false;
	});
	
});