$j(document).ready(function(){

	var togglePlayPause = function() {
		var linkNode = $$('#rotator_status a')[0];
		
		if(arguments[0] == "pause" || linkNode.className == "pause") {
			//cycler is currently playing, pause play back.
			linkNode.className = "play";
			$j('#storyRotator').cycle('pause');
		}else{
			linkNode.className = "pause";
			$j('#storyRotator').cycle('resume');
		}
	};
	
	$j.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) { 
	    $j(pager).find('li').removeClass('selectedButton') 
	        .filter('li:eq('+currSlideIndex+')').addClass('selectedButton'); 
	};
	
	
	$j('#storyRotator').cycle({
		fx: 'fade',
		speed: 'slow',
		timeout: 6000,
		pager: '#storyRotatorNav',
		cleartypeNoBg: 'false',
	    pause: 0,     // true to enable "pause on hover" 
	    pauseOnPagerHover: 0, // true to pause when hovering over pager link 
		pagerAnchorBuilder: function(idx, slide) {
			return '<li class="button">&nbsp;</li>';
		}
	});

	$j('#storyRotatorNav li.button').click(function() {
		togglePlayPause('pause');
	});
	
	var controls = Builder.node('div', {'id': 'rotator_status'},[
	                    Builder.node('a', {'href': '#', 'class':'pause'},["Play / Pause"])
	               ]);

	$j('#storyRotator_wrapper').append(controls);

	$j('#rotator_status a').click(function() {
		togglePlayPause();
		return false;
	});

	$j('#qcalendar').datepicker({
			format: 'Y-m-d',
			onSelect: function(date) {
				window.location.replace("events.php?date=" + date);
			}
	});

	$j('#cont img[t]').qtip({
	  content: {
		 text: false // Use each elements title attribute
	  },
	  style: 'cream'
	});

    $j('#commentform').submit(function(){
        $j.post(
            "ajax_blogcomment.php",
            $j("#commentform").serialize(),
            function(data){
                if (data.success) {
                    $j("div#commentform_message").css({'color':'green'});
					$j("#ccomment").val('');
				}
                else
                    $j("div#commentform_message").css({'color':'red'});
                $j("div#commentform_message").html(data.message);
            },
            "json"
        );
    });

	$j('#webpollform').submit(function(){
        $j.post(
            "ajax_webpollvote.php",
            $j("#webpollform").serialize(),
            function(data){
                if (data.success) {
					webpoll_switchscreens();
				}
            },
            "json"
        );
    });

});