/**
 * Javascript for Default Theme
 */
$(document).ready(function(){
//    $("ul.sf-menu").supersubs({
//        minWidth:    12,                                // minimum width of sub-menus in em units
//        maxWidth:    27,                                // maximum width of sub-menus in em units
//        extraWidth:  1                                  // extra width can ensure lines don't sometimes turn over
//    }).superfish({
//        delay:       400,                               // delay on mouseout
//        animation:   {opacity:'show',height:'show'},    // fade-in and slide-down animation
//        speed:       'fast',                            // faster animation speed
//        autoArrows:  false,                             // disable generation of arrow mark-up
//        dropShadows: false                              // disable drop shadows
//    });
	
	$('.slideshow').cycle({
		fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});

	$('#subNav ul li').addClass($('body').attr('class'));
    $('#subNav ul li a').addClass($('body').attr('class'));

    $('#datePicker').datepicker({
    	dateFormat: "dd-mm-yy",
    	onSelect: function(dateText, inst) {
    		window.location = '/whats-on/?date='+dateText;
    	}		
    });

    $('#search').click(function(){
    	$(this).val('');
    	$(this).css('color','#000');
    });

    $('#newsletter').click(function(){
    	$(this).val('');
    });
    
    $('#showPerformances').click(function(e){
    	$('table#bookPerformances').toggle();
    	e.preventDefault();
    });

    $('#search').blur(function(){
    	if ($(this).val() == '') {
	    	$(this).val('search');
	    	$(this).css('color','#aaa');
    	}
    });

    $('#newsletter').blur(function(){
    	if ($(this).val() == '') $(this).val('your email address');
    });

    $('body').supersleight({shim: '/img/x.gif'});

    var url = document.location.href.split('/');
    url = url[3] == 'whats-on' ? 'whats-on' : url[url.length-1];
    if (url) $('#nav ul li a[href*="/'+url+'"]').addClass($('body').attr('class')).closest('li').addClass($('body').attr('class'));

    $('select#quickEvent').change(function(){
		if ($(this).val() > 0) {
			$.getJSON("/performances/getlist/" + $(this).val() + '.json', {}, function(j){
				options = null;
				for (var i = 0; i < j.length; i++) {
					options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
				}
				$("select#quickPerformance").html(options);
			});
		}
	});
    
    $('#quickSubmit').click(function(e){
    	if ($("select#quickPerformance").val() > 0) {
    		window.open(bookUrl.replace('[EID]', $("select#quickPerformance").val()), "bookWindow");
    	}
    	else {
    		alert('Please select a show & performance');
    	}
    	e.preventDefault();
    });
});
