// Cufon headline replacement
jQuery(function($){
	Cufon.replace('h1, h2, h3, h4, ul#globalnav, #menutab, .scrollbutton' , {hover:true});
	Cufon.replace('body.sponsor h2, body.sponsor h3' , {color:'#000'});
});

// Full-size background image

jQuery(function($){
	$.fn.supersized.options = {  
		startwidth: 3,  
		startheight: 2,
//		vertical_center: 1,
		slideshow: 0
	};
    $('#supersize').supersized(); 
});

// Red background for Red Carpet page

jQuery(function($){
	var myLoc = window.location.toString();
	
	
if (myLoc === "http://statetheatrecompany.com.au/ticketssubs/types-of-subscriptions/red-carpet-subscription?layout=item")
		{
			$('div#supersize').html('<img src="/images/stories/red_bg.jpg" alt="" />');
		}
	else if (myLoc === "http://www.statetheatrecompany.com.au/ticketssubs/types-of-subscriptions/red-carpet-subscription?layout=item")
		{
			$('div#supersize').html('<img src="/images/stories/red_bg.jpg" alt="" />');
		}


});

// Hide and show menu 

/*
jQuery.fn.menuHide = function($){
	$('#header').addClass('closed');
	$('#header').prepend('<div id="menutab"><a href="#">Menu</a></div>');
	$('body.showpage div#header.closed').css('top' , '-110px');
	$('body.showpage div#header.closed div#menutab a').live('mouseover', function(){
	$('body.showpage div#header').animate({'top' : '0px'}, 300);
	$('body.showpage div#header').removeClass("closed");
	$('body.showpage div#header').addClass("open");
	});
	
	$('body.showpage div#header.open div#menutab a').live('click', function(){
	$('body.showpage div#header').animate({'top' : '-110px'}, 300);
	$('body.showpage div#header').removeClass("open");
	$('body.showpage div#header').addClass("closed");
	});
};
*/


// Superfish dropdown menu 

$(document).ready(function($){ 
        $("ul#globalnav").superfish({ 
            animation: {opacity:'show'},  
            delay:     400,   
            pathClass: 'active',
            autoArrows: false,        
            dropShadows: false 
        }); 
    }); 
    
// Contact form


jQuery(function($){
	$('input').bind("focus", function(){
		var val = $(this).val();
	
		if(val == "Your name" || val == "Your email" || val == "Message subject")
			{
				$(this).val("");
			}
	});
	$('div#contact_form input#submit').bind('click', function(){
		$('div#contact_form input').fadeOut(300);
		$('p.confirmation').fadeIn(300);
	});
});    

// Resizes scroll panels on show pages to fit copy

$.fn.scrollSize = function(){
	var myHeight = $('div.itemFullText').height() + 130 + "px";
	$('.scroll').css("height" , myHeight);
};

// Fixes sidebar height 

/*
jQuery(function($){
	var myHeight = $('div#maincol').height() + "px";
	$('div#sidebar').css("height" , myHeight);
});
*/

// Custom scrollers on spread content pages 


// when the DOM is ready...
$.fn.scroller = function() {
	 var panels = $('#slider .scrollContainer > div');
    var container = $('#slider .scrollContainer');

    // if false, we'll float all the panels left and fix the width 
    // of the container
    var horizontal = true;

    // float the panels left if we're going horizontal
    if (horizontal) {
        panels.css({
            'float' : 'left',
            'position' : 'relative' // IE fix to ensure overflow is hidden
        });

        // calculate a new width for the container (so it holds all panels)
        container.css('width', panels[0].offsetWidth * panels.length);
    }

    // collect the scroll object, at the same time apply the hidden overflow
    // to remove the default scrollbars that will appear
    var scroll = $('#slider .scroll').css('overflow', 'hidden');

    // apply our left + right buttons
  /*
  scroll
        .before('<a class="scrollButtons scrollLeft" href="">Left</a>')
        .before('<a class="scrollButtons scrollRight" href="">Right</a>');
*/

    // handle nav selection
    function selectNav() {
        $(this)
            .parents('ul:first')
                .find('a')
                    .removeClass('selected')
                .end()
            .end()
            .addClass('selected');

    }

    $('#slider .navigation').find('a').click(selectNav);

    // go find the navigation link that has this target and select the nav
    function trigger(data) {
    	
        var el = $('#slider .navigation').find('a[href$="' + data.id + '"]').get(0);
        selectNav.call(el);
    }

    if (window.location.hash) {
        trigger({ id : window.location.hash.substr(1) });
        
    } else {
        $('ul.navigation a:first').click();
    }

    // offset is used to move to *exactly* the right place, since I'm using
    // padding on my example, I need to subtract the amount of padding to
    // the offset.  Try removing this to get a good idea of the effect
    var offset = parseInt((horizontal ? 
        container.css('paddingTop') : 
        container.css('paddingLeft')) 
        || 0) * -1;


    var scrollOptions = {
        target: scroll, // the element that has the overflow

        // can be a selector which will be relative to the target
        items: panels,

        navigation: '.navigation a',

        // selectors are NOT relative to document, i.e. make sure they're unique
        prev: 'a.scrollLeft', 
        next: 'a.scrollRight',

        // allow the scroll effect to run both directions
        axis: 'x',

        onAfter: trigger, // our final callback

        offset: 0,
        
        /*
force: true,
        
        interval: 500,
*/

        // duration of the sliding effect
        duration: 500,

        // easing - can be used with the easing plugin: 
        // http://gsgd.co.uk/sandbox/jquery/easing/
        easing: 'easeInOutQuad'
    };


    // apply serialScroll to the slider - we chose this plugin because it 
    // supports// the indexed next and previous scroll along with hooking 
    // in to our navigation.
    $('#slider').serialScroll(scrollOptions);

    // now apply localScroll to hook any other arbitrary links to trigger 
    // the effect
    $.localScroll(scrollOptions);

    // finally, if the URL has a hash, move the slider in to position, 
    // setting the duration to 1 because I don't want it to scroll in the
    // very first page load.  We don't always need this, but it ensures
    // the positioning is absolutely spot on when the pages loads.
    scrollOptions.duration = 1;
    $.localScroll.hash(scrollOptions);
    
    // Shows slider and hides loader
  /*
  $('div#slider.services').css("visibility" , "visible");
	$('div#loader').hide();
*/
};
