/**
 * common theme behaviours
 * 
 */
 
jQuery(document).ready(function($){
	$("*").removeClass("marinelli-hide-no-js"); // remove the hide class (see common.css)
});;
/**
 * Top region js
 * bartext and bartext2 come from theme settings through template.php
 */
jQuery(document).ready(function($) {

  	// Hide region (don't hide in the demo block page)
	if(!Drupal.settings.marinelli.blockdemo){
		$('#topBar').hide();
	}
	
	// set the right text in the blcok demo page
	if(Drupal.settings.marinelli.blockdemo){
		$('#topBarLink a').text("↑ " + Drupal.settings.marinelli.bartext2 + "");
	}
	
	// Make the spy effect
	$('#topBarLink a').live('mouseover mouseout', function(event) {
    if (event.type == 'mouseover' && $(this).text() == "↓ " + Drupal.settings.marinelli.bartext + "") {
      $('#topBarLink').animate({
        'padding-top':'5px'
      });
    }
    else if (event.type == 'mouseout' && $(this).text() == "↓ " + Drupal.settings.marinelli.bartext + "") {
    $('#topBarLink').animate({
      'padding-top':'0px'
    });
    }
	});
  
	// Click logics
	$('#topBarLink a').click(function () {
    if ($(this).text()=="↓ " + Drupal.settings.marinelli.bartext + "") {
      $(this).text("↑ " + Drupal.settings.marinelli.bartext2 + "");
      $(this).attr('title','Close this region');
    }
    else if ($(this).text()=="↑ " + Drupal.settings.marinelli.bartext2 + "") {
      $(this).text("↓ " + Drupal.settings.marinelli.bartext + "");
      $(this).attr('title','Open this region');
    }
    $('#topBar').slideToggle("slow");
    return false;
  });

	// Link positioning
	var linkWidth = $('#topBarLink a').width();
	var windowWidth = $(window).width();

  	// Set start margin
	$('#topBarLink a').css('margin-left', ((windowWidth / 2) - (linkWidth / 2) -10) + 'px');

	$(window).bind('resize', function(event) {
		$('#topBarLink a').css('margin-left', (($(window).width() / 2) - (linkWidth / 2) - 10) + 'px');
	});

});;
/*
News ticker plugin (BBC news style)
Bryan Gullan,2007-2010
version 2.2
updated 2010-04-04
Documentation at http://www.makemineatriple.com/news-ticker-documentation/
Demo at http://www.makemineatriple.com/jquery/?newsTicker
Use and distrubute freely with this header intact.
*/
(function(a){function c(b){tickerData=a(b.newsList).data("newsTicker");if(tickerData.currentItem>tickerData.newsItemCounter){tickerData.currentItem=0}else if(tickerData.currentItem<0){tickerData.currentItem=tickerData.newsItemCounter}if(tickerData.currentPosition==0){if(tickerData.newsLinks[tickerData.currentItem].length>0){a(tickerData.newsList).empty().append('<li><a href="'+tickerData.newsLinks[tickerData.currentItem]+'"></a></li>')}else{a(tickerData.newsList).empty().append("<li></li>")}}if(tickerData.animating){if(tickerData.currentPosition%2==0){var d=tickerData.placeHolder1}else{var d=tickerData.placeHolder2}if(tickerData.currentPosition<tickerData.newsItems[tickerData.currentItem].length){var e=tickerData.newsItems[tickerData.currentItem].substring(0,tickerData.currentPosition);if(tickerData.newsLinks[tickerData.currentItem].length>0){a(tickerData.newsList+" li a").text(e+d)}else{a(tickerData.newsList+" li").text(e+d)}tickerData.currentPosition++;setTimeout(function(){c(b);b=null},tickerData.tickerRate)}else{if(tickerData.newsLinks[tickerData.currentItem].length>0){a(tickerData.newsList+" li a").text(tickerData.newsItems[tickerData.currentItem])}else{a(tickerData.newsList+" li").text(tickerData.newsItems[tickerData.currentItem])}setTimeout(function(){if(tickerData.animating){tickerData.currentPosition=0;tickerData.currentItem++;c(b);b=null}},tickerData.loopDelay)}}else{var e=tickerData.newsItems[tickerData.currentItem];if(tickerData.newsLinks[tickerData.currentItem].length>0){a(tickerData.newsList+" li a").text(e)}else{a(tickerData.newsList+" li").text(e)}}}var b="newsTicker";jQuery.fn[b]=function(d){var e=jQuery.extend({},jQuery.fn.newsTicker.defaults,d);var f=new Array;var g=new Array;var h=0;a(e.newsList+" li").hide();a(e.newsList+" li").each(function(){if(a(this).children("a").length){f[h]=a(this).children("a").text();g[h]=a(this).children("a").attr("href")}else{f[h]=a(this).text();g[h]=""}h++});var i=a(e.newsList);i.data(b,{newsList:e.newsList,tickerRate:e.tickerRate,startDelay:e.startDelay,loopDelay:e.loopDelay,placeHolder1:e.placeHolder1,placeHolder2:e.placeHolder2,controls:e.controls,ownControls:e.ownControls,stopOnHover:e.stopOnHover,newsItems:f,newsLinks:g,newsItemCounter:h-1,currentItem:0,currentPosition:0,firstRun:1}).bind({stop:function(a){tickerData=i.data(b);if(tickerData.animating){tickerData.animating=false}},play:function(a){tickerData=i.data(b);if(!tickerData.animating){tickerData.animating=true;setTimeout(function(){c(tickerData);tickerData=null},tickerData.startDelay)}},resume:function(a){tickerData=i.data(b);if(!tickerData.animating){tickerData.animating=true;tickerData.currentPosition=0;tickerData.currentItem++;c(tickerData)}},next:function(d){tickerData=i.data(b);a(tickerData.newsList).trigger("stop");tickerData.currentPosition=0;tickerData.currentItem++;c(tickerData)},previous:function(d){tickerData=i.data(b);a(tickerData.newsList).trigger("stop");tickerData.currentPosition=0;tickerData.currentItem--;c(tickerData)}});if(e.stopOnHover){i.bind({mouseover:function(c){tickerData=i.data(b);if(tickerData.animating){a(tickerData.newsList).trigger("stop");if(tickerData.controls){a(".stop").hide();a(".resume").show()}}}})}tickerData=i.data(b);if(tickerData.controls||tickerData.ownControls){if(!tickerData.ownControls){a('<ul class="ticker-controls"><li class="play"><a href="#play">Play</a></li><li class="resume"><a href="#resume">Resume</a></li><li class="stop"><a href="#stop">Stop</a></li><li class="previous"><a href="#previous">Previous</a></li><li class="next"><a href="#next">Next</a></li></ul>').insertAfter(a(tickerData.newsList))}a(".play").hide();a(".resume").hide();a(".play").click(function(b){a(tickerData.newsList).trigger("play");a(".play").hide();a(".resume").hide();a(".stop").show();b.preventDefault()});a(".resume").click(function(b){a(tickerData.newsList).trigger("resume");a(".play").hide();a(".resume").hide();a(".stop").show();b.preventDefault()});a(".stop").click(function(b){a(tickerData.newsList).trigger("stop");a(".stop").hide();a(".resume").show();b.preventDefault()});a(".previous").click(function(b){a(tickerData.newsList).trigger("previous");a(".stop").hide();a(".resume").show();b.preventDefault()});a(".next").click(function(b){a(tickerData.newsList).trigger("next");a(".stop").hide();a(".resume").show();b.preventDefault()})}a(tickerData.newsList).trigger("play")};jQuery.fn[b].defaults={newsList:"#news",tickerRate:80,startDelay:100,loopDelay:3e3,placeHolder1:" |",placeHolder2:"_",controls:true,ownControls:false,stopOnHover:true}})(jQuery);

