
/* - myscripts.js - */

/////////////////

//images overlay
jq(function(){
	jq('.zoom-image a, .image-wrapper a')
	    .prepOverlay({
		    subtype: 'image',
			urlmatch: '/image_view_fullscreen$',
			urlreplace: '_large'
			
	});
});

jq(function(){
	jq('#content .image-inline, #content .image-right, #image-wrapper a, .news-item.news-innerContainer a img')
	    .prepOverlay({
		    subtype: 'image',
			urlmatch: '/image_mini$',
			urlreplace: '/image_large'
			
	});
});

jq(function(){
	jq('.event-image')
	    .prepOverlay({
		    subtype: 'image',
			urlmatch: '/image_preview$',
			urlreplace: '/image_large'
			
	});
});
/*
jq(function(){
    jq('#otherNewsTicker a').prepOverlay({
        subtype: 'ajax',
        // selector:'#otherNews',
        urlmatch:'$',
        urlreplace:' #otherNews > *'
    });
});
*/


////////////////////
//Interstitial Popup
// Set up jQuery actions


// Set up jQuery actions
jq(document).ready(function() {
    // Display the popup after a delay
    setTimeout(interstitial_do_popup, 1000);
 
    // Ways to close the popup
    // Click the X
    jq("#interstitial_close").click(function(){
        interstitial_hide_popup();
    });
    // Click the background
    jq("#interstitial_background").click(function(){
        interstitial_hide_popup();
    });
    // Press escape
    jq(document).keypress(function(e){
        if(e.keyCode==27)
            interstitial_hide_popup();
    });
});


//0 means hidden; 1 means shown
var interstitial_popup_status = 0;
 
 
// Show the popup
function interstitial_show_popup() {
    // If our cookie is set, do nothing
    // Show the popup only if it is not currently displayed
    if(interstitial_popup_status == 0) {
        // only display this if our cookie is unset
        //var val = jq.cookie('interstitial_popup')
         var val = readCookie('interstitial_popup_facebook1')
        if (val == null) {
            // set the cookie to expire in a day
            //jq.cookie('interstitial_popup', 1, { expires: 1})
            createCookie('interstitial_popup_facebook1',1,1);
 
            jq("#interstitial_background").css({
                "opacity": "0.65"
            });
            jq("#interstitial_background").fadeIn("slow");
            jq("#interstitial_container").slideDown("slow");
 
            
 
            tb_interstitial_popup_status = 1;
        }
    }
}
 
// Hide the popup
function interstitial_hide_popup() {
    // Hide the popup if it is currently displayed
    if(tb_interstitial_popup_status == 1){
        jq("#interstitial_background").fadeOut("slow");
        jq("#interstitial_container").slideUp("slow");
        interstitial_popup_status = 0;
    }
}
 
// Position the popup
function interstitial_position_popup() {
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = jq("#interstitial_container").height();
    var popupWidth = jq("#interstitial_container").width();
    // Set the CSS to centerit
    var top = windowHeight*0.3-popupHeight/2;
    var left = windowWidth/2-popupWidth/2;
    if (top < 10) top = 10;  // Don't go above the top of the window
    jq("#interstitial_container").css({
        "position": "absolute",
        "top": top,
        "left": left
    });
 
    //only need force for IE6
    jq("#interstitial_background").css({
        "height": windowHeight
    });
}
 
function interstitial_do_popup() {
    interstitial_position_popup();
    interstitial_show_popup();
}
 
/************************/

 window.onload = function () {
            var container = $('#highlight-slider');
            var ul = $('ul.sliderGalleryList', container);
            
            var itemsWidth = ul.innerWidth() - container.outerWidth();
            
            jq('div.slider', container).slider({
                min: 0,
                max: itemsWidth,
                handle: '.handle',
                stop: function (event, ui) {
                    ul.animate({'left' : ui.value * -1}, 500);
                },
                slide: function (event, ui) {
                    ul.css('left', ui.value * -1);
                }
            });
       
            

            var div = $('div.sliderGallery'),
                ul = $('ul.sliderGalleryList'),
                ulPadding = 15;

            //Get menu width
            var divWidth = div.width();

             //Remove scrollbars 
            div.css({overflow: 'hidden'});

             //Find last image container
             var lastLi = ul.find('li:last-child');

//When user move mouse over menu
    div.mousemove(function(e){
        //As images are loaded ul width increases,
        //so we recalculate it each time
        var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;
        var left = (e.pageX - div.offset().left - ulPadding) * (ulWidth-divWidth+3*ulPadding) / divWidth;
        div.scrollLeft(left);
        var Slider = $('div.slider');
        var Handle = $('div.handle');
        var right = (e.pageX - Slider.offset().left + ulPadding) * (Slider.width()-Handle.width()-ulPadding) / Slider.width();
        Handle.css('left', right);

    });



 };







/**************Carousel *********/

/*
jq(document).ready(function(){	
		$("#slider").easySlider({
			controlsBefore:	'<p id="controls">',
			controlsAfter:	'</p>',
			auto: true, 
			continuous: true,
			prevText:'',
			nextText:'',
			orientation:'vertical'

			});
});

*/


jq(function(){
		jq('#tabMainFrame')
		  .each(function(){
		  	jq(this)
			 .children('tabMemberType');
			 
		  });
		  
		jq('#tabMainFrame')
		  .tabs(
		    '#tabMemberType',
			{
				tabs: '.memberTypeTitle',
				effect: 'fade'
			}
		);
	});
	

jq(function(){
		jq('#tabMembrosEleitos')
		  .each(function(){
		  	jq(this)
			 .children('tabPartidoEleito');
			 
		  });
		  
		jq('#tabMembrosEleitos')
		  .tabs(
		    '#tabPartidoEleito',
			{
				tabs: '.partyTabTitle',
				effect: 'fade'
			}
		);
	});
	

jq(function(){
		jq('#tabMembrosInerencia')
		  .each(function(){
		  	jq(this)
			 .children('tabPartidoInerencia');
			 
		  });
		  
		jq('#tabMembrosInerencia')
		  .tabs(
		    '#tabPartidoInerencia',
			{
				tabs: '.partyTabTitle',
				effect: 'fade'
			}
		);
	});


jq(function(){
	jq('.member a, #municipal_assembly_president a, .municipal_assembly_secretary_name')
	    .prepOverlay({
		    subtype: 'ajax'
		});
});






jq(document).ready(function(){
				
				//Full Caption Sliding (Hidden to Visible)
				jq('.boxgrid.captionfull').hover(function(){
					jq(".cover", this).stop().animate({top:'120px'},{queue:false,duration:160});
				}, function() {
					jq(".cover", this).stop().animate({top:'170px'},{queue:false,duration:160});
				});
				//Caption Sliding (Partially Hidden to Visible)
				jq('.boxgrid.caption').hover(function(){
					jq(".cover", this).stop().animate({top:'120px'},{queue:false,duration:160});
				}, function() {
					jq(".cover", this).stop().animate({top:'215px'},{queue:false,duration:160});
				});
			});
	
//Snowing script	
//jq(document).ready(function(){
//$("#visual-portal-wrapper").snowing();
//});	


//++++++++++News ticker ++++++++++++
jQuery.fn.liScroll = function(settings) {
        settings = jQuery.extend({
        travelocity: 0.07
        }, settings);
        return this.each(function(){
                var $strip = jQuery(this);
                $strip.addClass("newsticker")
                var stripWidth = 0;
                var $mask = $strip.wrap("<div class='mask'></div>");
                var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");
                var containerWidth = $strip.parent().parent().width();  //a.k.a. 'mask' width   
                $strip.find("li").each(function(i){
                stripWidth += jQuery(this, i).outerWidth(true); // thanks to Michael Haszprunar
                });
                $strip.width(stripWidth);
                var totalTravel = stripWidth+containerWidth;
                var defTiming = totalTravel/settings.travelocity;   // thanks to Scott Waye     
                function scrollnews(spazio, tempo){
                $strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
                }
                scrollnews(totalTravel, defTiming);
                $strip.hover(function(){
                jQuery(this).stop();
                },
                function(){
                var offset = jQuery(this).offset();
                var residualSpace = offset.left + stripWidth;
                var residualTime = residualSpace/settings.travelocity;
                scrollnews(residualSpace, residualTime);
                });
        });
};

$(function(){
    $("ul#newsTicker01").liScroll();
});


$(function(){
    $("ul#newsTicker02").liScroll();
});


$(document).ready(function() {

    function highlightNo(arg) {

       var caller = arg;
        var number = caller.getCurrentID();
/*        if(number==0) {
            $("#previous").attr("disabled", "disabled");
            $("#next").removeAttr("disabled");
        } else {
            $("#next, #previous").removeAttr("disabled");
        }
*/
        jq("#counter li").attr('class', 'inactive');
        jq("#counter li").fadeTo(0, 0.5, function(){        });
        jq("#counter li img").css('filter', 'alpha(opacity=50)');
        jq("#counter li:eq("+(number)+")").attr('class', 'active');
        jq("#counter li:eq("+(number)+")").fadeTo(0, 1, function(){        });
        jq("#counter li:eq("+(number)+") img").css('filter', 'alpha(opacity=100)');


 }

   var divHeight0 = jq('#box0');
   var divHeight1 = jq('#box1');
   var divHeight2 = jq('#box2');
   var divHeight3 = jq('#box3');
   tempHeight = 445;
   if (divHeight0.height() >= divHeight1.height() && divHeight0.height() >= divHeight2.height() && divHeight0.height() >= divHeight3.height()) {
        tempHeight = divHeight0.height();
    }
   else if (divHeight1.height() >= divHeight0.height() && divHeight1.height() >= divHeight2.height() && divHeight1.height() >= divHeight3.height()) {
        tempHeight = divHeight1.height();
    }
    else if (divHeight2.height() >= divHeight0.height() && divHeight2.height() >= divHeight1.height() && divHeight2.height() >= divHeight3.height()) {
        tempHeight = divHeight1.height();
    }
    else {
        tempHeight = divHeight3.height();
    }
//   alert(divHeight0.height() + '+' + divHeight1.height() + '+' + divHeight2.height() +  divHeight3.height() + '=' + tempHeight);

//        tH = parseInt(tempHeight);

   if (tempHeight < 250) {
    tempHeight = 445
   }

   mcarousel = $("#mycarousel").msCarousel({boxClass:'div.box', height:tempHeight+5, width:755, callback:highlightNo, autoSlide:5000}).data("msCarousel");
   //add event on number
   //alert($("#mycarousel").{height}));
   jq("#counter li").click(function() {
        if(mcarousel!=undefined) {
            var no = $(this).attr('counter');
            mcarousel.goto(parseInt(no));

        }
   });


  jq('#counter li').mouseover(function() {
        if(mcarousel!=undefined) {
            mcarousel.pause();
           $(this).fadeTo(0, 1, function(){        });
        }
   });

  jq('#counter li img').mouseover(function() {
        if(mcarousel!=undefined) {
            mcarousel.pause();
           $(this).css('filter', 'alpha(opacity=100)');

        }
   });


   jq("#counter li").mouseout(function() {
        if(mcarousel!=undefined) {
            mcarousel.play();
            if ($(this).attr('class') == 'inactive'){
                $(this).fadeTo(0, 0.5, function(){        });
            }
        }
   });

   jq("#counter li").mouseout(function() {
        if(mcarousel!=undefined) {
            mcarousel.play();
            if ($(this).attr('class') == 'inactive'){
                $(this).find('img').css('filter', 'alpha(opacity=50)');

         }
        }
   });

    jq("#next").click(function() {
        mcarousel.next();
    });
    jq("#previous").click(function() {
        mcarousel.previous();
    });
    jq("#next, #previous").attr("disabled","disabled");

})
			


