/** master js file **/

// Define energetic namespace
var E = {};

// jQuery onload
$(document).ready(function() {
	
	// RSS icon hover
	if($('.rss_box').length != 0) {
		E.rssIconHover();
	}
	// Facebook icon hover
	if($('.fb_box').length != 0) {
		E.fbIconHover();
	}
	// Twitter icon hover
	if($('.twitter_box').length != 0) {
		E.twitterIconHover();
	}
	// Lokalisten icon hover
	if($('.lokalisten_box').length != 0) {
		E.lokalistenIconHover();
	}
		
	// Twitter feed
	if($('.rightside_twitter').length != 0) {
		E.twitterFeed();
	}
	
	// Media chooser
	if($('.mbox').length != 0) {
		E.mediaChooser();
	}
	
	// Init navi box
	if($('.rs_navi_box').length != 0) {
		E.initNaviBox();
	}
	
	// Fancybox
	$('a.fancybox').fancybox({
		'zoomSpeedIn': 300,
		'zoomSpeedOut': 100,
		'overlayShow': false,
		'padding': 10
	});
});


// RSS icon hover
E.rssIconHover = function() {
	var img = $('.rss_box .rss_img');
	var picPath = img.attr('src');
	img.hover(
		function() {
			$(this).attr('src', $(this).attr('src').replace(/.jpg/g, '_hover.jpg'));
		},
		function() {
			$(this).attr('src', picPath);
		}
	);
}
// Facebook icon hover
E.fbIconHover = function() {
	var img = $('.fb_box .fb_img');
	var picPath = img.attr('src');
	img.hover(
		function() {
			$(this).attr('src', $(this).attr('src').replace(/.jpg/g, '_hover.jpg'));
		},
		function() {
			$(this).attr('src', picPath);
		}
	);
}
// Twitter icon hover
E.twitterIconHover = function() {
	var img = $('.twitter_box .twitter_img');
	var picPath = img.attr('src');
	img.hover(
		function() {
			$(this).attr('src', $(this).attr('src').replace(/.jpg/g, '_hover.jpg'));
		},
		function() {
			$(this).attr('src', picPath);
		}
	);
}
// Lokalisten icon hover
E.lokalistenIconHover = function() {
	var img = $('.lokalisten_box .lokalisten_img');
	var picPath = img.attr('src');
	img.hover(
		function() {
			$(this).attr('src', $(this).attr('src').replace(/.jpg/g, '_hover.jpg'));
		},
		function() {
			$(this).attr('src', picPath);
		}
	);
}

// Twitter feed
E.twitterFeedCount = 5;
E.twitterFeed = function() {
	getTwitters('tweet', { 
	  id: 'energetic_band', 
	  count: E.twitterFeedCount, 
	  enableLinks: true, 
	  clearContents: true,
	  newwindow: true,
	  prefix: '%user_profile_image_url% sagt: ',
	  template: '<div class="prefix"><img height="16" width="16" src="%user_profile_image_url%" /> <a href="http://twitter.com/%user_screen_name%">%user_screen_name%</a> said: </div> <span class="status">"%text%"</span>'
	  //template: '%text% <div class="meta">%time%</div>'
	});
}

/** Media chosser **/
E.mediaChooser = function() {
	$('.mbox a').hover(
		function() {
			$(this).children().attr('src', $(this).children().attr('src').replace(/.jpg/g, '_h.jpg'));
		},
		function() {
			$(this).children().attr('src', $(this).children().attr('src').replace(/_h.jpg/g, '.jpg'));
		}
	);
}

/** Navi box **/
E.initNaviBox = function() {
	$(".rs_navi_box .q-cabl").click(function() {
		$(this).nextAll('ul').slideToggle('fast', function() {
			$(this).prevAll('img.q-cabl').toggleClass('q-exp');
		});
	});
}