/*

	jQuery.Events
	James.Bunker@EvolvingAgency.com
	20 April 2010

*/

var dropStatus = false;
var firstTime = false;
var analytics = false;

$(document).ready(function(){

	$('#features a').live('click',function() { googlePush('/action/carousel/'+$(this).attr('rel')); });

	$('#leaderboard a').live('click',function() { googlePush('/action/leaderboard/'+$(this).find('img').attr('alt')+'/from:'+window.location.href); });

	$('#right a').live('click',function() { googlePush('/action/skyscraper/'+$(this).find('img').attr('alt')+'/from:'+window.location.href); });

	$('.js_msg').remove();

	$('a[href*=.pdf]').live('click',function() { googlePush($(this).attr('href')); });

	$('.whats_on_panel').hide();

	$('#hot_offers').show();

	//$('#offerCodeData').slideUp();

	$("#ticker ul").newsTicker(3000);

	$('#whats_on_selector a').live('click',function(){ var url = '/action/whats_on' + $(this).attr('href'); googlePush(url); $('#whats_on_selector li').removeClass('on'); $(this).parent().addClass('on'); $('.whats_on_panel').hide(); $($(this).attr('href')).show(); return false; });

	$('#trigger_advanced_search').toggle(function(){ $.get('/ajax?action=AdvancedSearch&_frameset=true',function(data){ $('#search_form').html(data); }); $(this).html('Simple search'); googlePush('/action/advanced-search'); return false; },function(){ $.get('/ajax?action=SimpleSearch&_frameset=true',function(data){ $('#search_form').html(data); }); $(this).html('Advanced search'); googlePush('/action/simple-search'); return false; });

	$('#simple_search form').submit(function(){ var c = 'home-search-shows'; var a = 'find-shows'; var l = $('#drop_down_holder a.top').html(); _gaq.push(['_trackEvent',c,a,l]); });

	$('.js_date a').live('click',function(){ var a = $(this).parent().parent().find('a.date'); calendar(a); return false; });

	$('.clear_date').live('click',function(){ var a = $(this).parent().find('a.date'); $('#'+a.attr('id')).text('Any date'); $('#'+a.attr('rel')).val(''); $(this).remove(); updateSearch(); return false; });

	$('#menu_wrapper').find('.menu_items').hide().first('.menu_items').show();

	$('#menu_wrapper a').live('click',function(){ $('#menu_wrapper').find('.menu_items').hide(); $('#menu_wrapper li').removeClass('on'); $($(this).attr('href')).show(); $(this).parent().addClass('on'); doCufon(); return false;	});

	if($('.thinner').length > 0){ $.get('/ajax?action=SimpleSearchThinner&_frameset=true',function(data){ $('#search_form').html(data); }); }else if($('#buy_tix').length > 0){ $.get('/ajax?action=AdvancedSearch&_frameset=true&'+unescape(window.location.search.substring(1)),function(data){ $('#search_form').html(data); }); } else { $.get('/ajax?action=SimpleSearch&_frameset=true',function(data){ $('#search_form').html(data); }); }

	$('.callvenue').live('click',function(){ $('#blockUI_content').html('<div class="callvenue">'+"Call the Box Office on 0844 844 044 to book for tonight's show. Online bookings have closed.</div>"); $.blockUI({ message: $('#blockUI') }); return false; });

	$('#blockUI_close span').live('click',function(){ $.unblockUI(); });

	if($('#venue_map').length > 0){ var id = $('#venue_map').attr('rel'); $.getJSON('/ajax?action=mapDynamic&_frameset=true&id='+id,function(d){ $('#venue_map').googlemap(d); }); }

/*	if($('#venue_map_small').length > 0){ var id = $('#venue_map_small').attr('rel'); $.getJSON('/ajax?action=mapDynamicSmall&id='+id,function(d){ $('#venue_map_small').googlemap(d); }); }	*/

	if($('#venues_map').length > 0){ $.getJSON('/ajax?action=FullMapDynamic&_frameset=true',function(d){ $('#venues_map').googlemap(d); }); }

	$('.image_change').live('click',function(){ $.get('/ajax?action=galleryImage&_frameset=true&id='+$(this).attr('rel'),function(d){ $('#image_holder').html(d); }); var selected = $('#image_holder').find('a').attr('rel'); $('#thumbs_list a').removeClass('selected'); $('#thumbs_list a[rel='+selected+']').addClass('selected'); return false; });

	$('input#offerCode').live('keyup',function(){ checkBasicOfferCode($(this).val()); });

	$('.thickbox').live('click',function(){ $.get($(this).attr('href')+'&_frameset=true',function(data){ $('#blockUI_content').html(data); $.blockUI({ message: $('#blockUI') }); $('.scroll-pane').jScrollPane(); }); doCufon(); return false;});

	$('#features a').live('click',function(){ googlePush($(this).attr('href') + '?f=' + $(this).parents('li').attr('class')); });

	$('input.help').load(function(){ $(this).addClass('soft'); $(this).val($(this).attr('title')); });

	$('input.help').focus(function(){ if($(this).val() == $(this).attr('title')) { $(this).removeClass('soft'); $(this).val(''); } }).blur(function(){ if($(this).val() == '') { $(this).addClass('soft'); $(this).val($(this).attr('title')); } });

	$('#newsletter_form').submit(function(){ $.post('/ajax?_frameset=true',$(this).serializeArray(),function(d){ $('#newsletter_target').html(d); }); return false; });

	$('.gallery_demo_unstyled').addClass('gallery_demo');

	if($('.drop_down').length > 0) { $('.drop_down_holder a.top').toggle( function(){ var dropStatus = true; }, function closeDropDown(){ var dropStatus = false; } ); $('.drop_down_holder a.top').live('click',function(){ if (dropStatus == false){ $(this).parent().find('div.drop_down').animate({height: 'show'}, 200, function(){ $(this).parent().find('div.drop_down ul').css({overflow:'auto'}); }); $(this).parent().find('div.drop_down ul').css({overflow:'hidden'}); $(this).addClass('active'); dropStatus = true; }else{ $(this).parent().find('div.drop_down ul').css({overflow:'hidden'}); $(this).parent().find('div.drop_down').animate({height: 'hide'}, 200); $(this).removeClass('active'); dropStatus = false; } return false; }); $('.drop_down_holder ul a').live('click',function() { var newTitle = $(this).text(); $('#'+$(this).attr('rel')).find('a.top').text(newTitle); $('#'+$(this).attr('rel')).find('div.drop_down ul').css({overflow:'hidden'}); $('#'+$(this).attr('rel')).find('div.drop_down').animate({height: 'hide'}, 200); $('#'+$(this).attr('rel')).find('a.top').removeClass('active'); dropStatus = false; submitForm($(this).attr('href'),newTitle,$(this).attr('rel')); return false; }); $('*[class!="top"]').live('click',function(){ $('div.drop_down').animate({height: 'hide'}, 200); $('div.drop_down ul').css({overflow:'hidden'}); $('.drop_down_holder a.top').removeClass('active'); dropStatus = false; }); }

	if($('ul.thumbs').length > 0) { var onMouseOutOpacity = 0.67; $('#thumbs ul.thumbs li').opacityrollover({ mouseOutOpacity: onMouseOutOpacity, mouseOverOpacity: 1.0, fadeSpeed: 'fast', exemptionSelector: '.selected' }); var gallery = $('#thumbs').galleriffic({ delay: 2500, numThumbs: 15, preloadAhead: 10, enableTopPager: true, enableBottomPager: true, maxPagesToShow: 7, imageContainerSel: '#slideshow', controlsContainerSel: '#controls', captionContainerSel: '#caption', loadingContainerSel: '#loading', renderSSControls: true, renderNavControls: true, playLinkText: 'Play Slideshow', pauseLinkText: 'Pause Slideshow', prevLinkText: '&lsaquo; Previous Photo', nextLinkText: 'Next Photo &rsaquo;', nextPageLinkText: 'Next &rsaquo;', prevPageLinkText: '&lsaquo; Prev', enableHistory: false, autoStart: false, syncTransitions: true, defaultTransitionDuration: 900, onSlideChange: function(prevIndex, nextIndex) { this.find('ul.thumbs').children().eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end().eq(nextIndex).fadeTo('fast', 1.0); }, onPageTransitionOut: function(callback) { this.fadeTo('fast', 0.0, callback); }, onPageTransitionIn: function() { this.fadeTo('fast', 1.0); } }); }

	$('#features').jcarousel({scroll: 1, visible: 3, auto: 3, wrap: 'circular', animation: 'slow', initCallback: mycarousel_initCallback});

	$('#features li a').hover(function() { $li = $(this).parents('li.jcarousel-item'); $li.addClass('on'); $('.feature_text',$li).addClass('on'); $('.feature_text_long',$li).show(); $('.feature_text_short',$li).hide(); },function(){ $li = $(this).parents('li.jcarousel-item'); $('.feature_text', $li).removeClass('on'); $('.feature_text_long',$li).hide(); $('.feature_text_short',$li).show(); });

	if($('#FRE_rating').length > 0) { $("#FRE_rating").stars({inputType: "select",cancelShow: false}); }

	//$('.email_pref').click(function(){ var $child = $(this).find('input'); if($child.is(':checked')) { $child.attr('checked',false); $(this).removeClass('selected');  } else { $child.attr('checked',true); $(this).addClass('selected'); }}).hover(function(){ $(this).addClass('hover'); },function(){ $(this).removeClass('hover'); });

	$('.email_pref input').change(function(){ if($(this).is(':checked')) $(this).parent().parent().addClass('selected'); else $(this).parent().parent().removeClass('selected'); });
	
	$('#reasonForm').hide();
	$('#more_reasons').hide();
	
	$('#showReasonForm').click(function(){
		$('#reasonForm').fadeIn();
		return false;
	});
	
	$('#reason_other').change(function(){
		if($(this).is(':checked'))
			$('#more_reasons').fadeIn();
		else
			$('#more_reasons').fadeOut();
	});

	updateSearch();

});

function submitForm(id,name,which) { var e = id.substring(strpos(id,'#')+1); switch(which) { case 'venue': $('input#venue_id').val(e); break; case 'show_type': $('input#show_type_id').val(e); break; } updateSearch(); }
function googlePush(u,t) { if(t == null) { t = '_trackPageview'; } _gaq.push([t,u]); }
function updateSearch() { if($('#searchcount').length > 0) { $.post('/ajax?action=SearchCount&_frameset=true',$('#ticketsform').serializeArray(),function(data) { $('#searchcount').html(data); }); } }
function checkBasicOfferCode(val) { if(val.length > 2){ $.get('/ajax?action=checkBasicOfferCode&_frameset=true&code='+escape(val)+'&_frameset=true',function(data) { $('#offerCodeData').html(data).slideDown('slow'); }); } else { $('#offerCodeData').html('').slideUp('slow'); } }
function send2friend(){ $.get('/ajax?_frameset=true',$('#ajaxSendFriend').serializeArray(),function(d) { $('#blockUI_content').html(d);}); return false; }
function calendar(e){if($('#'+e.attr('id')+"_div").length > 0) { return false; } timestamp = $('#'+e.attr('rel')).val(); container = e.attr('id'); target = 'insertDate'; c = document.getElementById(e.attr('id')); d = findPos(c); if(timestamp==undefined) timestamp = "false"; h = 210; w = 186; div = document.createElement('div'); div.id = e.attr('id')+"_div"; div.className = "calendarDiv"; div.style.position = "absolute"; div.style.margin = "-"+Math.round(h/2)+"px 0 0 -"+Math.round(w/2)+"px"; div.style.overflow = "visible"; div.style.zIndex = "1000"; iframe = document.createElement('iframe'); iframe.style.border = "none"; iframe.style.width = w+"px"; iframe.style.height = h+"px"; iframe.src = "/ajax?action=calendar&_frameset=true&fn="+target+"&c="+container+"&t="+timestamp; iframe.frameBorder = "no"; iframe.scrolling = "no"; div.style.top = ((d.Top-(h/2))-10)+'px'; div.style.left = ((d.Left)+5)+'px'; div.appendChild(iframe); document.body.appendChild(div); }
function insertDate(container,date){ var e = $('#'+container); var y = $('#'+e.attr('rel')); e.text(date); y.val(date); var p = e.parent(); if(date != '' && p.find('span.clear_date').length == 0) { p.find('a.date').before('<span class="clear_date replace">x</span>'); } div = document.getElementById(container+"_div"); div.parentNode.removeChild(div); updateSearch();}
function strpos (haystack, needle, offset){ var i = (haystack+'').indexOf(needle, (offset || 0)); return i === -1 ? false : i; }
function findPos(elm){ var x, y = 0; x = elm.offsetLeft; y = elm.offsetTop; elm = elm.offsetParent; while(elm != null){ x = parseInt(x) + parseInt(elm.offsetLeft); y = parseInt(y) + parseInt(elm.offsetTop); elm = elm.offsetParent; } return {Top:y, Left: x}; }
function mycarousel_initCallback(carousel){ carousel.buttonNext.bind('click',function(){carousel.startAuto(0);}); carousel.buttonPrev.bind('click',function(){carousel.startAuto(0);}); carousel.clip.hover(function(){ carousel.stopAuto(); },function(){ carousel.startAuto(); }); }


