// when the DOM is ready...

var Vars="Empty";
/* var lastPlayed="";

function playerReady(obj) {
	if(Vars['file']!=lastPlayed)
	{
		lastPlayed=Vars['file'];
		document.getElementById('cpplayer').sendEvent('LOAD',Vars);
	}
};

*/

$(document).ready(function () {
  //  $.ui.dialog.defaults.bgiframe = true;


    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;
	var Vars="";

    // 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('<img class="scrollButtons left" src="http://www.creativepostinc.com/wp/wp-content/themes/tvelements-dark/images/prev.png" />')
        .after('<img class="scrollButtons right" src="http://www.creativepostinc.com/wp/wp-content/themes/tvelements-dark/images/next.png" />');

    // 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;

	$('#kingspeaks').live('click', function(){
		$('#vprewindow').dialog('open');
		$("span.ui-dialog-title").text('The King Speaks'); 
		Vars={file:'http://www.creativepostinc.com/wp/wp-content/uploads/2011/07/KingSpeaks.m4v'};
		setTimeout(function() {$('#cpplayer')[0].sendEvent('LOAD',Vars);$('#cpplayer')[0].sendEvent('PLAY');}, 500);
	});

	$('#doncherry').live('click', function(){
		$('#vprewindow').dialog('open');
		$("span.ui-dialog-title").text('The Don Cherry Story'); 
		Vars={file:'http://www.creativepostinc.com/wp/wp-content/uploads/2011/07/DONCHERRY.m4v'};
		setTimeout(function() {$('#cpplayer')[0].sendEvent('LOAD',Vars);$('#cpplayer')[0].sendEvent('PLAY');}, 500);
	});

	$('#hefner').live('click', function(){
		$('#vprewindow').dialog('open');
		$("span.ui-dialog-title").text('Hugh Hefner'); 
		Vars={file:'http://www.creativepostinc.com/wp/wp-content/uploads/2011/07/HEFNER.m4v'};
		setTimeout(function() {$('#cpplayer')[0].sendEvent('LOAD',Vars);$('#cpplayer')[0].sendEvent('PLAY');}, 500);
	});

	$('#bloodrayne').live('click', function(){
		$('#vprewindow').dialog('open');
		$("span.ui-dialog-title").text('Bloodrayne'); 
		Vars={file:'http://www.creativepostinc.com/wp/wp-content/uploads/2011/07/BLOODRAYNE.m4v'};
		setTimeout(function() {$('#cpplayer')[0].sendEvent('LOAD',Vars);$('#cpplayer')[0].sendEvent('PLAY');}, 500);
	});

	$('#wdytya').live('click', function(){
		$('#vprewindow').dialog('open');
		$("span.ui-dialog-title").text('Who Do You Think You Are'); 
		Vars={file:'http://www.creativepostinc.com/wp/wp-content/uploads/2011/07/WDYTYA.m4v'};
		setTimeout(function() {$('#cpplayer')[0].sendEvent('LOAD',Vars);$('#cpplayer')[0].sendEvent('PLAY');}, 500);
	});

	$('#acacia').live('click', function(){
		$('#vprewindow').dialog('open');
		$("span.ui-dialog-title").text('Acacia'); 
		Vars={file:'http://www.creativepostinc.com/wp/wp-content/uploads/2011/07/ACACIA.m4v'};
		setTimeout(function() {$('#cpplayer')[0].sendEvent('LOAD',Vars);$('#cpplayer')[0].sendEvent('PLAY');}, 500);
	});

	$('#skinny').live('click', function(){
		$('#vprewindow').dialog('open');
		$("span.ui-dialog-title").text('Skinny Bitch'); 
		Vars={file:'http://www.creativepostinc.com/wp/wp-content/uploads/2011/07/SKINNYBITCH.m4v'};
		setTimeout(function() {$('#cpplayer')[0].sendEvent('LOAD',Vars);$('#cpplayer')[0].sendEvent('PLAY');}, 500);
	});

	$('#apparitions').live('click', function(){
		$('#vprewindow').dialog('open');
		$("span.ui-dialog-title").text('Apparitions'); 
		Vars={file:'http://www.creativepostinc.com/wp/wp-content/uploads/2011/07/APPARITIONS.m4v'};
		setTimeout(function() {$('#cpplayer')[0].sendEvent('LOAD',Vars);$('#cpplayer')[0].sendEvent('PLAY');}, 500);
	});

	$('#indie').live('click', function(){
		$('#vprewindow').dialog('open');
		$("span.ui-dialog-title").text('How To Be Indie'); 
		Vars={file:'http://www.creativepostinc.com/wp/wp-content/uploads/2011/07/HTBI.m4v'};
		setTimeout(function() {$('#cpplayer')[0].sendEvent('LOAD',Vars);$('#cpplayer')[0].sendEvent('PLAY');}, 500);
	});

	$('#coronation').live('click', function(){
		$('#vprewindow').dialog('open');
		$("span.ui-dialog-title").text('Coronation Street'); 
		Vars={file:'http://www.creativepostinc.com/wp/wp-content/uploads/2011/07/CORONATION.m4v'};
		setTimeout(function() {$('#cpplayer')[0].sendEvent('LOAD',Vars);$('#cpplayer')[0].sendEvent('PLAY');}, 500);
	});

	$('#pom').live('click', function(){
		$('#vprewindow').dialog('open');
		$("span.ui-dialog-title").text('The Power of Myth'); 
		Vars={file:'http://www.creativepostinc.com/wp/wp-content/uploads/2011/07/POM.m4v'};
		setTimeout(function() {$('#cpplayer')[0].sendEvent('LOAD',Vars);$('#cpplayer')[0].sendEvent('PLAY');}, 500);
	});

	$('#howie').live('click', function(){
		var uename="howie";
		$("span.ui-dialog-title").text('Howie Gold'); 
		$('#biowindow').html("<img name='bioimg' src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-howie-off.jpg' onmouseover=\"document.images['bioimg'].src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-howie-on.jpg'\" onmouseout=\"document.images['bioimg'].src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-howie-off.jpg'\" onClick=\"parent.location='mailto:" + uename + "@creativepostinc.com'\">");
		$('#biowindow').dialog('open');
	});

	$('#ken').live('click', function(){
		var uename="ken";
		$("span.ui-dialog-title").text('Ken MacNeil'); 
		$('#biowindow').html("<img name='biok' src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-ken-off.jpg' onmouseover=\"document.images['biok'].src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-ken-on.jpg'\" onmouseout=\"document.images['biok'].src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-ken-off.jpg'\" onClick=\"parent.location='mailto:" + uename + "@creativepostinc.com'\">");
		$('#biowindow').dialog('open');
	});

	$('#ahmad').live('click', function(){
		var uename="ahmad";
		$("span.ui-dialog-title").text('Ahmad Ismail'); 
		$('#biowindow').html("<img name='biok' src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-ahmad-off.jpg' onmouseover=\"document.images['biok'].src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-ahmad-on.jpg'\" onmouseout=\"document.images['biok'].src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-ahmad-off.jpg'\" onClick=\"parent.location='mailto:" + uename + "@creativepostinc.com'\">");
		$('#biowindow').dialog('open');
	});

	$('#tony').live('click', function(){
		var uename="tony";
		$("span.ui-dialog-title").text('Tony Yue'); 
		$('#biowindow').html("<img name='biok' src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-tony-off.jpg' onmouseover=\"document.images['biok'].src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-tony-on.jpg'\" onmouseout=\"document.images['biok'].src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-tony-off.jpg'\" onClick=\"parent.location='mailto:" + uename + "@creativepostinc.com'\">");
		$('#biowindow').dialog('open');
	});

	$('#jana').live('click', function(){
		var uename="jana";
		$("span.ui-dialog-title").text('Jana Knezu'); 
		$('#biowindow').html("<img name='biok' src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-jana-off.jpg' onmouseover=\"document.images['biok'].src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-jana-on.jpg'\" onmouseout=\"document.images['biok'].src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-jana-off.jpg'\" onClick=\"parent.location='mailto:" + uename + "@creativepostinc.com'\">");
		$('#biowindow').dialog('open');
	});

	$('#gloria').live('click', function(){
		var uename="gloria";
		$("span.ui-dialog-title").text('Gloria Walman'); 
		$('#biowindow').html("<img name='biok' src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-gloria-off.jpg' onmouseover=\"document.images['biok'].src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-gloria-on.jpg'\" onmouseout=\"document.images['biok'].src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-gloria-off.jpg'\" onClick=\"parent.location='mailto:" + uename + "@creativepostinc.com'\">");
		$('#biowindow').dialog('open');
	});

	$('#dan').live('click', function(){
		var uename="dan";
		$("span.ui-dialog-title").text('Dan Duffin'); 
		$('#biowindow').html("<img name='biok' src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-dan-off.jpg' onmouseover=\"document.images['biok'].src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-dan-on.jpg'\" onmouseout=\"document.images['biok'].src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-dan-off.jpg'\" onClick=\"parent.location='mailto:" + uename + "@creativepostinc.com'\">");
		$('#biowindow').dialog('open');
	});

	$('#gord').live('click', function(){
		var uename="gord";
		$("span.ui-dialog-title").text('Gord Ventura'); 
		$('#biowindow').html("<img name='biok' src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-gord-off.jpg' onmouseover=\"document.images['biok'].src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-gord-on.jpg'\" onmouseout=\"document.images['biok'].src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-gord-off.jpg'\" onClick=\"parent.location='mailto:" + uename + "@creativepostinc.com'\">");
		$('#biowindow').dialog('open');
	});

	$('#jeremy').live('click', function(){
		var uename="jeremy";
		$("span.ui-dialog-title").text('Jeremy Kay'); 
		$('#biowindow').html("<img name='biok' src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-jeremy-off.jpg' onmouseover=\"document.images['biok'].src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-jeremy-on.jpg'\" onmouseout=\"document.images['biok'].src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-jeremy-off.jpg'\" onClick=\"parent.location='mailto:" + uename + "@creativepostinc.com'\">");
		$('#biowindow').dialog('open');
	});

	$('#steve').live('click', function(){
		var uename="steve";
		$("span.ui-dialog-title").text('Steve Micheli'); 
		$('#biowindow').html("<img name='biok' src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-steve-off.jpg' onmouseover=\"document.images['biok'].src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-steve-on.jpg'\" onmouseout=\"document.images['biok'].src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-steve-off.jpg'\" onClick=\"parent.location='mailto:" + uename + "@creativepostinc.com'\">");
		$('#biowindow').dialog('open');
	});

	$('#mike').live('click', function(){
		var uename="mikem";
		$("span.ui-dialog-title").text('Mike Menard'); 
		$('#biowindow').html("<img name='biok' src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-mike-off.jpg' onmouseover=\"document.images['biok'].src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-mike-on.jpg'\" onmouseout=\"document.images['biok'].src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-mike-off.jpg'\" onClick=\"parent.location='mailto:" + uename + "@creativepostinc.com'\">");
		$('#biowindow').dialog('open');
	});

	$('#maria').live('click', function(){
		var uename="mkelenc";
		$("span.ui-dialog-title").text('Maria Kelenc'); 
		$('#biowindow').html("<img name='biok' src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-maria-off.jpg' onmouseover=\"document.images['biok'].src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-maria-on.jpg'\" onmouseout=\"document.images['biok'].src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-maria-off.jpg'\" onClick=\"parent.location='mailto:" + uename + "@creativepostinc.com'\">");
		$('#biowindow').dialog('open');
	});

	$('#gabor').live('click', function(){
		var uename="gabor";
		$("span.ui-dialog-title").text('Gabor Zoltan'); 
		$('#biowindow').html("<img name='biok' src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-gabor-off.jpg' onmouseover=\"document.images['biok'].src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-gabor-on.jpg'\" onmouseout=\"document.images['biok'].src='http://www.creativepostinc.com/wp/wp-content/uploads/2011/08/cp-bios-gabor-off.jpg'\" onClick=\"parent.location='mailto:" + uename + "@creativepostinc.com'\">");
		$('#biowindow').dialog('open');
	});

	function setFname(fName){

Vars=fName;
};

	$('#vprewindow').dialog({
		autoOpen: false,
		resizable: false,
		height: 388,
		width: 630,
		modal: true
});

	$('#biowindow').dialog({
		autoOpen: false,
		resizable: false,
		height: 388,
		width: 630,
		modal: true
});
	


    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: 'img.left', 
        next: 'img.right',

        // allow the scroll effect to run both directions
        axis: 'xy',

        onAfter: trigger, // our final callback

        offset: offset,

        // duration of the sliding effect
        duration: 500,

        // easing - can be used with the easing plugin: 
        // http://gsgd.co.uk/sandbox/jquery/easing/
        easing: 'swing'
    };

    // 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);
    // auto scroll
var cycleTimer = setInterval(function () {
   $scroll.trigger('next');
}, 15000);

});
