/*
	Angling International
	common.js

	Copyright Exists (c), Brave Creative, all rights reserved.
*/
$(function() {

	// nth-child, margin fixes etc
	$('.navigation li:first-child, #three ul li:first').css('paddingLeft', 0);
	$('.navigation li:last-child').css({paddingRight: 0, background: 'transparent'});
	
	$('#left ul li a:first, #right ul li:first-child, .box ul li:first-child').css('marginTop',0);
	
	$('#right .postswimg li:last, #three ul li:last').css({border: 0});
	
	$('#postsplain ul li:last-child').css({border: 0, marginBottom: 0, paddingBottom: 0});
	
	$('#tradeCats li:nth-child(4n)').css('marginRight', 0);
	$('#shelf ul li:nth-child(5n), #videos.normal ul li:nth-child(3n), #videos.latest-panel ul li:nth-child(5n)').css('marginRight', 0);
	
	
	
	//$('#left #menu-main-navigation').prepend('<li><a href="http://www.angling-international.com">Home <span></span></li>');
	
	// -->
	
	// Search Field Functions - Clear onfocus - restore to original onblur
	$('input[type=text]').each( function(){
		var input = $(this); var inputVal = input.val();	
		input.focus( function(){ if( input.val() != inputVal ) { return false; } input.val(''); } );
		input.blur( function(){ if( input.val() == '' ) { input.val( inputVal ); } } );	
	} );
	// -->	
	
	// dropdown menus
	function showMenu() {$(this).children('.dropdown').show();}
	function hideMenu() {$(this).children('.dropdown').hide();}
	$('.navigation li').hoverIntent(showMenu, hideMenu);
	// -->
	
	// homepage slider
	$('.slides').bxSlider({auto: true, speed: 600, pause: 13000, mode: 'vertical', autoStart: true, pager: true});
	// -->
	
	// Misc fx
	$('#left .socialButtons a').css('opacity', 0.4);
	$('#left .socialButtons a:last').css('marginRight', 0);
	$('#left .socialButtons a').hover(function(){$(this).css('opacity',1);}, function(){$(this).css('opacity',0.4);});
	
	$('#posts .post p:last-child').css('marginBottom',0);
	
	$('.chief').css('opacity', 0.3);
	$('.chief').hover(function(){ $(this).stop().animate({opacity: 1, height: 119, top: '-134px'}, 500); }, function(){ $(this).stop().animate({opacity: 0.3, height: 60, top: '-74px'}, 300); });
	
	$('.goingup').click(function(){$('html, body').animate({scrollTop:0}, 'slow');return false;});
	
	$('#shelf ul li img').hover(function(){$(this).stop().animate({marginTop: '-17px'}, 300);},function(){$(this).stop().animate({marginTop: '0px'}, 200);});
	
	$('#posts .post.page.single table tr:first td').addClass('head');
	$('#posts .post.page.single table tr:not(first):nth-child(odd)').addClass('alt');
	
	// -->
	
	// resize
	if ((screen.width>=1100)) {
	}
	else  {
	$('#sticky, #band').hide();
	}
	// -->
	
	// Latest mag slideOut
	$('#sticky span, #sticky .slideOut').hover( function(){$('.slideOut').stop().animate({left: '-85px'}, 300);},function(){$('.slideOut').stop().animate({left: '-105px'}, 300);} );
	//-->
	
	// Tweet feed
	$(".tweet").tweet({
					username: "AnglingIntMag",
					join_text: "auto",
					count: 5,
					auto_join_text_default: "",
					auto_join_text_ed: "",
					auto_join_text_ing: "",
					auto_join_text_reply: "",
					auto_join_text_url: "",
					loading_text: "<br />Twitter is loading..."
				});	
	// -->
	
	// EFTTEX Carousel etc
    $('#efttexcarousel').cycle({delay: 2000, speed: 1000, timeout: 6000});
    // -->
    
    // Content height hax for disqus
    var leftHeight = $('#left').height();
    var contentHeight = $('#content').height();
    if(contentHeight > leftHeight) {
    	$('#respond').css({float: 'none', padding: 0, width: '100%', paddingTop: '20px', clear: 'both'});
    	$('.dsq-trackback-url').css('width', '990px');
    }    
    // -->
    
    // Fancybox Galleries (videos & article media)
    // Article Media
	$("a[rel=article-gallery]").fancybox({
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',	
		'titlePosition'		: 'outside',
		'overlayColor'		: '#000',
		'overlayOpacity'	: 0.85,
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) { return '<span id="fancybox-title-over"><span class="index">Image ' + (currentIndex + 1) + ' / ' + currentArray.length+'</span>' + (title.length ? ' &nbsp; ' + title : '') + '</span>';},
		'titlePosition': 'over',
		'autoScale'   :	true,
		'autoDimensions' :   true,
		'centerOnScroll' :   true			
	});    
	
	// Video Popup (AJAX)
	$("a.view-full").fancybox({
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',	
		'overlayColor'		: '#000',
		'overlayOpacity'	: 0.85,
		'autoScale'   :	true,
		'autoDimensions' :   true,
		'centerOnScroll' :   true		
	}); 	
    // -->

});
