        var obama_feeds, mccain_feeds, obama_video_feeds, mccain_video_feeds;
        var indicator = '<img src="media/images/indicator.gif" alt="loading" />';
        var big_indicator = '<div style="text-align:center; height:90%;margin:20px 0;" class="indic"><img src="media/images/ajax-loader.gif" alt="loading" /></div>';
        var loaded_panels = new Array();
        Array.prototype.find = function (element)
				{
				  for (var keys in this)
				  {
				      if (this[keys] == element)
				    {
				      return keys;
				      break;
				    }
				  }
				  return -1;
				}
        $().ready(function(){
          $('.media').media();
          // tab list
          $('#page').accordion({header: 'a.tab', autoheight: false, navigation: true});
          // feed feeder
          $('#news_link').click(function(){
            obamaFeeds(document);
            mccainFeeds(document);
          });
          
          $('#video_link').click(function(){
            obamaVideos();
            mccainVideos();
          });
          
          
          $('a.refresh').click(function(){
            var elem = $(this).attr('rel');
            if(elem == 1)
              obamaFeeds();
            else
              mccainFeeds();
            
            return false;
          });
          
          $('a.refresh_video').click(function(){
            var elem = $(this).attr('rel');
            if(elem == 1)
              obamaVideos();
            else
              mccainVideos();
            
            return false;
          });
          
          $('a.tab').click(function(){
          	var elem = $(this).attr('rel');
          	// rel niteliği dolu ise
          	if('' !== elem)
          	{
          		if(loaded_panels.find(elem) == -1)
          		{
          			loaded_panels.push(elem);
          			$("#"+elem).append(big_indicator);
	              $("#"+elem).load("load.php?p="+elem,
	                function() {
	                  
	                }
	              );
          		}
          	}
          });
          
        });
        
        function whenDocumentReady(context)
        {
        	$('div.news_detail a', context).unbind("click");
        	$('div.news_detail a', context).click(function(){
        		// linkin href niteliği
        		 //var t = this.title || this.innerHTML || this.href;
        		 var href =  $(this).attr('href');
        		 $(this).attr('href', '#GB_window');
             var val  = $(this).html();
		         GB_show(val,href,600,800);
		         location.href = '#GB_window';
		         return false;
        	});
        }
        
        function obamaVideos()
        {
          $('#indicator3').html(indicator);
          $.getFeed({
            url: 'feed.php?f=3',
            success: function(videos){
              obama_video_feeds = videos;
              loadVideoItem('obama', 0);
              var elems = '<ul>';
              $.each(videos.items, function(i, n){
            elems += '<li><a href="javascript:void(0);" onclick="loadVideoItem(\'obama\', '+i+')">'+n.title+'</a></li>';
          });
          $('#obama_videos > div.news_list').html(elems+'</ul>');
          $('#indicator3').html('');
            }
          });
        }
        
        function mccainVideos()
        {
          $('#indicator4').html(indicator);
          $.getFeed({
            url: 'feed.php?f=4',
            success: function(videos){
              mccain_video_feeds = videos;
              loadVideoItem('mccain', 0);
              var elems = '<ul>';
              $.each(videos.items, function(i, n){
            elems += '<li><a href="javascript:void(0);" onclick="loadVideoItem(\'mccain\', '+i+')">'+n.title+'</a></li>';
          });
          $('#mccain_videos > div.news_list').html(elems+'</ul>');
          $('#indicator4').html('');
            }
          });
        }

        function obamaFeeds(context)
        {
          $('#indicator1').html(indicator);
          $.getFeed({
            url: 'feed.php?f=1',
            success: function(news){
              obama_feeds = news;
              loadFeedItem('obama', 0);
              var elems = '<ul>';
              $.each(news.items, function(i, n){
		            elems += '<li><a href="javascript:void(0);" onclick="loadFeedItem(\'obama\', '+i+')">'+n.title+'</a></li>';
		          });
		          $('#obama_news > div.news_list').html(elems+'</ul>');
		          $('#indicator1').html('');
		          whenDocumentReady(context);
            }
          });
        }
        
        function mccainFeeds(context)
        {
          $('#indicator2').html(indicator);
          $.getFeed({
            url: 'feed.php?f=2',
            success: function(news){
              mccain_feeds = news;
              loadFeedItem('mccain', 0);
              var elems = '<ul>';
              $.each(news.items, function(i, n){
	            elems += '<li><a href="javascript:void(0);" onclick="loadFeedItem(\'mccain\', '+i+')">'+n.title+'</a></li>';
		          });
		          $('#mccain_news > div.news_list').html(elems+'</ul>');
		          $('#indicator2').html('');
		          whenDocumentReady(context);
            }
          });
        }
        
        function loadVideoItem(feed_elem, item)
        {
          feed = '';
          div = '';
          if(feed_elem == 'obama')
          {
            feed = obama_video_feeds;
            div = 'obama_video_holder';
          }
          else if(feed_elem == 'mccain')
          {
            feed = mccain_video_feeds;
            div = 'mccain_video_holder';
          }
          // video linki adam gibi olsun
          var vid = feed.items[item].link;
          vid = vid.replace(/watch\?v\=/, 'v/');
          $('#'+div).html('<h3>'+feed.items[item].title+'</h3><span class="date">'+feed.items[item].updated+'</span><div class="videobox"><a href="'+vid+'" class="media">'+feed.items[item].title+'</a></div>');
          //$('a.media').media({autoplay: false, caption: false, type:'swf'});
          
          $('#'+div+' > div.videobox > a.media').flash(
              { height: 370, width: 450 },
              { version: 8 },
              function(htmlOptions) {
                  $this = $(this);
                  htmlOptions.src = $this.attr('href');
                  $this.before($.fn.flash.transform(htmlOptions));            
              }
          );

          

        }        
        
        function loadFeedItem(feed_elem, item)
        {
          feed = '';
          div = '';
          if(feed_elem == 'obama')
          {
            feed = obama_feeds;
            div = 'obama_news_holder';
          }
          else if(feed_elem == 'mccain')
          {
            feed = mccain_feeds;
            div = 'mccain_news_holder';
          }
          $('#'+div).html('<h3>'+feed.items[item].title+'</h3><p><span class="date">'+feed.items[item].updated+'</span>'+feed.items[item].description+'</p><a href="'+feed.items[item].link+'" class="detail-link">details...</a>');
          whenDocumentReady(document);
        }

   $(document).ready(function(){
				$('#obama_mccain').flash({ 
					src: 'media/images/vc.swf',
					width: 960,
					height: 300
				},
				{
					version: 9
				});
			});
		
		
var tooltip=function(){
	var id = 'tt';
	var top = 3;
	var left = 3;
	var maxw = 300;
	var speed = 10;
	var timer = 20;
	var endalpha = 95;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			tt.style.top = (u - h) + 'px';
			tt.style.left = (l + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();