// Beat Fly JavaScript core document
/*jquery setting*/
$(document).ready(function(){
	
	//Horizontal Sliding elements
	$('.boxgridelements.slideright').hover(function(){
		$(".coverelements", this).stop().animate({left:'280px'},{queue:false,duration:300});
			}, function() {
				$(".coverelements", this).stop().animate({left:'0px'},{queue:false,duration:300});
	});
	
	//img effect
	$('.boxgrid img, .portfolioThumb img.online, .videoThumb img, #socialnetwork li img').hover(function() {
		$(this).stop().animate({
			opacity : 0.5
		}, 500);
		},
		function(){
		$(this).stop().animate({
			opacity : 1
		}, 500);
	});
	
	//filter
	$('ul#filter a').click(function() {
		$(this).css('outline','none');
		$('ul#filter .current').removeClass('current');
		$(this).parent().addClass('current');
		
		var filterVal = $(this).text().toLowerCase().replace(' ','-');
				
		if(filterVal == 'all') {
			$('.portfolioThumb.hidden').fadeIn('slow').removeClass('hidden');
		} else {
			
			$('.portfolioThumb').each(function() {
				if(!$(this).hasClass(filterVal)) {
					$(this).fadeOut('normal').addClass('hidden');
				} else {
					$(this).fadeIn('slow').removeClass('hidden');
				}
			});
		}
		
		return false;
	});
	
	//twitter
	$(".tweet").tweet({
		join_text: "auto",
		username: "Beatfly",
	    avatar_size: 48,
	    count: 3,
		auto_join_text_default: "I said,", 
		auto_join_text_ed: "I",
		auto_join_text_ing: "I was",
	    auto_join_text_reply: "I replied",
	    auto_join_text_url: "I was checking out",
		loading_text: "loading Beatfly tweets..."
    });
	
	//flickr
	$.getJSON("http://api.flickr.com/services/feeds/photos_faves.gne?nsid=13019305@N00&lang=it-it&format=json&jsoncallback=?", displayImages);
	
	function displayImages(data) {																																   
		var iStart = Math.floor(Math.random()*(11));	
		var iCount = 0;								
		var htmlString = "<ul>";					
		$.each(data.items, function(i,item){
									
			if (iCount > iStart && iCount < (iStart + 7)) {
				
				var sourceSquare = (item.media.m).replace("_m.jpg", "_s.jpg");	
				
				htmlString += '<li><a href="' + item.link + '" target="_blank">';
				htmlString += '<img src="' + sourceSquare + '" alt="' + item.title + '" title="' + item.title + '"/>';
				htmlString += '</a></li>';
			}
			
			iCount++;
		});		
		
	$('#flickrbox').html(htmlString + "</ul>");
	
	}
	
	//bookmark
	$("a.jQueryBookmark").click(function(e){
		e.preventDefault(); // this will prevent the anchor tag from going the user off to the link
		var bookmarkUrl = this.href;
		var bookmarkTitle = this.title;
		 
		if (window.sidebar) { // For Mozilla Firefox Bookmark
			window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
		} else if( window.external || document.all) { // For IE Favorite
			window.external.AddFavorite( bookmarkUrl, bookmarkTitle);
		} else if(window.opera) { // For Opera Browsers
			$("a.jQueryBookmark").attr("href",bookmarkUrl);
			$("a.jQueryBookmark").attr("title",bookmarkTitle);
			$("a.jQueryBookmark").attr("rel","sidebar");
		} else { // for other browsers which does not support
			 alert('Your browser does not support this bookmark action');
			 return false;
		}
	});
	
	//png fix
	$('#logo h1 a, ul.idTabs li a:link, ul.idTabs li a:visited, ul.idTabs li a.selected, #myController span, #myController span.jFlowSelected, .linkPortfolio, .boxdescription, ul#filter li a, ul#filter li a span, ul#filter li.current a, ul#filter li.current span, .genericbox, .portfolioThumb, .portfolioThumb.parallel, .portfolio_detail, .top a span, .uno, .due, .tre, .quattro, .cinque, .cross, .cat, .filtercat, .news, .check, .chain, .video, .bullet, #breadcrumb li a, #breadcrumb li a span, a.singleswitch, a.singleswitch.alpha, a.fullswitch, a.fullswitch.alpha, a.single, a.single.alpha, #socialnetwork li img, #footer').addClass('unitPng');
	
	//text-shadow more
	$(".rightside h1, .rightside h2, .rightside h3, .rightside h4, .rightside h5, #intro h2, #intro h3, #intro h4, #news h4, .leftside h3, .leftside h4, #elements h5, a.anchorLink, .cover h3, .boxgridelements h3, span.Web, strong.Web, span.Graphic, strong.Graphic, span.Logotype, strong.Logotype, ul.generic_list li.Web, ul.generic_list li.Web a, ul.generic_list li.Graphic, ul.generic_list li.Graphic a, ul.generic_list li.Logotype, ul.generic_list li.Logotype a, #subfooterleft h6, #subfootermain h6, #subfooterright h6, #breadcrumb li#last, #socialnetwork p").css({"text-shadow":"2px 2px 3px #000"});
	
	//text-shadow less
	$("#menu li a, #subfooterend p, ul#filter li a").css({"text-shadow":"1px 1px 3px #000"});
	
	//img team hover effect
	$('li.imgages img, img.elements').mouseover(function() {
    	$(this).css({'border':'4px solid #a7afb9'});
        }).mouseout(function() {
        	$(this).css({'border':'4px solid #fff'});
    });
	
	//img thumb
	$('img.thumb').mouseover(function() {
    	$(this).css({'border':'3px solid #a7afb9'});
        }).mouseout(function() {
        	$(this).css({'border':'3px solid #fff'});
    });
	
	//news hover effect
	$('#news li').mouseover(function() {
    	$(this).css({'background-color':'#042c59'});
        }).mouseout(function() {
        	$(this).css({'background-color':'transparent'});
    });
	
	//genericbox hover effect
	$('.genericbox').mouseover(function() {
    	$(this).css({'border':'4px solid #A7AFB9'});
        }).mouseout(function() {
        	$(this).css({'border':'4px solid #022B59'});
    });
	
	//portfolioThumb hover effect
	$('.portfolioThumb').mouseover(function() {
    	$(this).css({'border-top':'1px solid #A7AFB9'});
        }).mouseout(function() {
        	$(this).css({'border-top':'1px solid #022B59'});
    });
		 
	/*toolbox portfolio features*/
    $(".singleswitch").click(function() {
    	$(".portfolioThumb dt.img").fadeIn();
		$(".portfolioThumb dd.metatag").fadeOut();
			$("a.singleswitch").addClass('alpha');
			$("a.fullswitch").removeClass('alpha');
    });
	
    $(".fullswitch").click(function() {
     	$(".portfolioThumb dt.img").fadeOut();
		$(".portfolioThumb dd.metatag").fadeIn();
			$("a.fullswitch").addClass('alpha');
			$("a.singleswitch").removeClass('alpha');
    });
	
	/*toolbox video features*/
	$('.portfolioThumb dd.metatag, .portfolioThumb dd.descrizione_videos').hide();
			
    $(".single").click(function() {
     	$(".portfolioThumb dt.img").fadeIn();
		$("a.fulllink").fadeIn();
		$(".portfolioThumb dd.descrizione_videos, .portfolioThumb dd.metatag").fadeOut();
		$(".portfolioThumb, dl").removeClass('parallel');
			$("a.single").addClass('alpha');
			$("a.full").removeClass('alpha');
    });
	
	$(".full, .fulllink").click(function() {
    	$(".portfolioThumb dt.img").fadeOut();
		$("a.fulllink").fadeOut();
		$(".portfolioThumb dd.descrizione_videos, .portfolioThumb dd.metatag").fadeIn();
		$(".portfolioThumb, dl").addClass('parallel');
			$("a.full").addClass('alpha');
			$("a.single").removeClass('alpha');
    });
	
	//focus form
	$("#name").focus();
	
//end		
});

//imageloader
	$(function () {
		$('.boxgrid img, .wrap_portfolioDetail img').hide();
	});
		
		var i = 0;
		var int=0;
		$(window).bind("load", function() {
			var int = setInterval("doThis(i)",500);
		});

		function doThis() {
			var imgs = $('img').length;
			if (i >= imgs) {
				clearInterval(int);
			}
			$('img:hidden').eq(0).fadeIn(500);
				$('.preload, .loading').fadeOut(500);
				i++;
		}


