﻿/* WEBPARTS AJAX PÁGINA PRINCIPAL - TABS E LISTA DE NOTICIAS DAS CAMARAS*/


(function($){
  $.extend({
    jGFeed : function(url, fnk, num, key){
      // Make sure url to get is defined
      if(url == null) return false;
      // Build Google Feed API URL
      var gurl = "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?&q="+url;
      if(num != null) gurl += "&num="+num;
      if(key != null) gurl += "&key="+key;
      // AJAX request the API
      $.getJSON(gurl, function(data){
        if(typeof fnk == 'function')
		  fnk.call(this, data.responseData.feed);
		else
		  return false;
      });
    }
  });
})(jQuery);


jQuery(document).ready(function() {


	//Default Action
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("ui-tabs-selected").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content
	$("#rotator").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 6000);
	
	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("ui-tabs-selected"); //Remove any "active" class
		$(this).addClass("ui-tabs-selected"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});

jQuery.jGFeed('http://www.multimedia.guarda.pt/conteudos-externos/rss/rss-guardapt-min.php',
function(feeds){
  // Check for errors
  if(!feeds){
    // there was an error
    return false;
  }
  // do whatever you want with feeds here
  for(var i=0; i<feeds.entries.length; i++){
    var entry = feeds.entries[i];
    // Entry title
    jQuery("#tab1").append("<div class='fitemcon'><div class='fitemimg'><a href='" + entry.link+ " '>" + entry.content + "</a></div><div class='fitemtxt'><a href='" + entry.link+ " '>" + entry.title + "</a></div></div>");
  }
}, 4);

jQuery.jGFeed('http://www.multimedia.guarda.pt/conteudos-externos/rss/rss-executivo-min.php',
function(feeds){
  // Check for errors
  if(!feeds){
    // there was an error
    return false;
  }
  // do whatever you want with feeds here
  for(var i=0; i<feeds.entries.length; i++){
    var entry = feeds.entries[i];
    // Entry title
    jQuery("#tab2").append("<div class='fitemcon'><div class='fitemimg'><a href='" + entry.link+ " '>" + entry.content + "</a></div><div class='fitemtxt'><a href='" + entry.link+ " '>" + entry.title + "</a></div></div>");
  }
}, 4);

jQuery.jGFeed('http://www.multimedia.guarda.pt/conteudos-externos/rss/rss-turismo-min.php',
function(feeds){
  // Check for errors
  if(!feeds){
    // there was an error
    return false;
  }
  // do whatever you want with feeds here
  for(var i=0; i<feeds.entries.length; i++){
    var entry = feeds.entries[i];
    // Entry title
    jQuery("#tab3").append("<div class='fitemcon'><div class='fitemimg'><a href='" + entry.link+ " '>" + entry.content + "</a></div><div class='fitemtxt'><a href='" + entry.link+ " '>" + entry.title + "</a></div></div>");
  }
}, 4);
jQuery.jGFeed('http://www.multimedia.guarda.pt/conteudos-externos/rss/rss-agroflorestal-min.php',
function(feeds){
  // Check for errors
  if(!feeds){
    // there was an error
    return false;
  }
  // do whatever you want with feeds here
  for(var i=0; i<feeds.entries.length; i++){
    var entry = feeds.entries[i];
    // Entry title
    jQuery("#tab4").append("<div class='fitemcon'><div class='fitemimg'><a href='" + entry.link+ " '>" + entry.content + "</a></div><div class='fitemtxt'><a href='" + entry.link+ " '>" + entry.title + "</a></div></div>");
  }
}, 4);


jQuery.jGFeed('http://www.multimedia.guarda.pt/conteudos-externos/rss/rss-guardapt-full.php',
function(feeds){
  // Check for errors
  if(!feeds){
    // there was an error
    return false;
  }
  // do whatever you want with feeds here
  jQuery("#cmlcontainer").append("<div class='titnotregiao'><a href='http://www.guarda.pt' target='_blank'>Notícias guarda.pt</a></div>");
  for(var i=0; i<feeds.entries.length; i++){
    var entry = feeds.entries[i];
    // Entry title
    jQuery("#cmlcontainer").append("<div class='flistitemcon'><div class='flistitemconleft'>" + entry.content + "</div><div class='flistitemconright'><a target='_blank' href='" + entry.link+ "'>" + entry.title + "</a></div></div>");
  }
}, 10);

$('.loadingPic').delay(1000).hide('slow')
});




