var sctructure = {
	init : function() {
		sctructure.lastTweet.init();
		sctructure.temas.init();
		sctructure.photoGallery.init();
		sctructure.authorNav.init();
		

		
	},
	
	bindings : {
		init : function() {
							
 
			
		}
	},
		
	temas : {
		init : function() {
			$('.choose-theme a').click(function(){
				$('#theme-menu').show();
								
				//$('#theme-menu').css('top','-'+$('#theme-menu').height());
								
				$('#main-wrapper').css('margin-top',$('#theme-menu').height());
				
				
				
				
				
				});
				
		
				$('#theme-menu .btn-close').click(function(){

					$('#theme-menu').hide();
     				$('#main-wrapper').css('margin-top',0);

					//location.href='/?BG='+$(this).attr('href');
					return false;
					
					});
				
				$('#theme-list a').click(function(){
					

					
//					$.ajax({
//    type: 'GET',
//	url: '/wp-admin/admin-ajax.php',
//    data: 'action=MarcaBG&BG='+$(this).attr('id'),
//    success: function( response ){
//		//alert(response);
//           }
//});


				$('body').removeClass('yellow');
				$('body').removeClass('red');
				$('body').removeClass('blue');
				$('body').addClass($(this).attr('id'));
				$.cookie('gptotal-bgc', $(this).attr('id'));
				return false;
				});

		}
	},
	
lastTweet: {
        init: function() {
            var setupTweet = {
                staticTweet: 'Carregando...',
                tweetUser: 'GPtotal'
            };

            function getTweet(obj) {
                // caching
                $.ajaxSetup({
                    cache: true
                });
                
				$('#wdg-twitter-msg').text(setupTweet.staticTweet);
				$.getJSON('http://api.twitter.com/1/statuses/user_timeline/'+setupTweet.tweetUser+'.json?count=1&callback=?',function(tweet) {
/*
					tweet = linkify(tweet[0].text);
					$(".tweet").html(tweet);
*/
                    lastTweet = tweet[0].text;
                    lastTweet = lastTweet.replace(/http:\/\/\S+/g, '<a href="$&" target="_blank">$&</a>');
                    lastTweet = lastTweet.replace(/\s(@)(\w+)/g, ' @<a href="http://twitter.com/$2" target="_blank">$2</a>');
					$('#wdg-twitter-msg').text('');
                    $('#wdg-twitter-msg').append(lastTweet);
				});
                
				//$('#wdg-twitter-user').text('@'+setupTweet.tweetUser)
				/*
                $.getJSON('http://search.twitter.com/search.json?callback=?&rpp=1&q=from:' + setupTweet.tweetUser, function(data) {
                    var lastTweet = data.results[0];
                    $('#wdg-twitter-msg').text('');
                    if (lastTweet !== undefined) {
                        lastTweet = data.results[0].text;
                        lastTweet = lastTweet.replace(/http:\/\/\S+/g, '<a href="$&" target="_blank">$&</a>');
                        lastTweet = lastTweet.replace(/\s(@)(\w+)/g, ' @<a href="http://twitter.com/$2" target="_blank">$2</a>');
                        $('#wdg-twitter-msg').append(lastTweet);
                    } else {
                        $('#wdg-twitter-msg').append(setupTweet.staticTweet)
                    }
                })
                */
            }
            getTweet(setupTweet);
        }
    }
	,
	photoGallery : {
		init : function() {
			$('#photo-holder img').load(function(){
				$(this).css('width',$(this).width()+'px');	
			});
			
			$('#photo-gallery .lst-thumbs-holder .lst-thumbs').width($('#photo-gallery .lst-thumbs-holder .lst-thumbs li').size()*130);
			$('#photo-gallery .lst-thumbs-holder').jScrollPane();
			$('#photo-gallery .lst-thumbs a').click(function() {
				var current_item =$(this).parent().parent();
				var ind=current_item.index();
				$('#photo-gallery .lst-thumbs li').removeClass('current-item');
				current_item.addClass('current-item');
				$('#photo-holder img').attr('src',$(this).attr('href'));
				$('#photo-holder .photo-label').text($(this).text());
				$('#photo-holder a').css('visibility','visible');
				if(ind==0){
					//$('#photo-holder div .btn-prior').css('visibility','hidden');
				}else{
					//if(($('#photo-gallery .lst-thumbs li').size()-1)==ind){
						//$('#photo-holder div .btn-next').css('visibility','hidden');
					//}
				}
				return false;
			});
			$('#photo-holder div .btn-next').click(function(){
				var el=$('#photo-gallery .lst-thumbs li.current-item').next().find('a');
				if(el.size()==0){
					$('#photo-gallery .lst-thumbs li:first').find('a').click();
				}else{el.click()}
//				$('#photo-gallery .lst-thumbs li.current-item').next().find('a').click();
			});
			$('#photo-holder div .btn-prior').click(function(){
			var el=$('#photo-gallery .lst-thumbs li.current-item').prev().find('a');
				if(el.size()==0){
					$('#photo-gallery .lst-thumbs li:last').find('a').click();
				}else{el.click()}

				});
				

			$('#photo-gallery ul li:first a').click();

//			var idMouseEventShowLabel = "#photo-holder";
//			if( $("#breaker-photo-holder").is("*") ) {
//				idMouseEventShowLabel = "#breaker-photo-holder";
//			}

			$("#breaker-photo-holder,#photo-holder").each(function() {
				$(this).mouseenter(function(e) {
					$(this).children(".button-label-holder").fadeIn();
				});
				
				$(this).mouseleave(function(e) {
					$(this).children(".button-label-holder").fadeOut();
				});
			});
		}
	},

	authorNav : {
		init : function() {
			$("#columnists .paged-list .paginator li a").click(function(e) {
				var page = $(this).attr("href").substr(1);
				var $filter = $(this).parents(".paged-list").find(".page-holder ul li");
				$filter.removeClass("onpage");
				$filter.parent().children(".page"+page).addClass("onpage");
				
				$(this).parent().siblings().children("a").removeClass("current");
				$(this).addClass("current");
				e.preventDefault();
			});
		}
	}
}
$(document).ready(function() {
	sctructure.init();
});
