function initMagazine() {
	if ($('#issue_flash_holder').size() > 0) {
		var flashvars = {};
		//var params = {wmode: 'transparent'};
		var params = {bgcolor: '#000000'};
		var attributes = {};
		var issue_id = $('#magazine_content h1').attr('id').split('_')[1];
		attributes.id = "issue_flash";		
		flashvars.config = "/xml/config.xml";
		flashvars.issueId = issue_id;
		swfobject.embedSWF("/swf/issue.swf", "issue_flash_holder", "1018", "660", "9.0.0", false, flashvars, params, attributes);
	}	
}


function initViewProfileGalleryLists() {
	var show = 2;
	$('div#profile_gallery_holder ul li:gt('+(show-1)+')').hide();
	$('div#profile_gallery_holder a.view_more').remove();
	if ($('div#profile_gallery_holder ul li').size() > show) {
		$('div#profile_gallery_holder ul').after('<a href="#" class="view_more">View all</a>');
	}
	$('div#profile_gallery_holder a.view_more').click(function() {
		$('div#profile_gallery_holder ul li:gt(1)').slideToggle();
		if ($(this).text() != 'Hide') {
			$(this).text('Hide');
		} else {
			$(this).text('View all');
		}
	}); 
}
function initViewProfileVideoLists() {
	var show = 1;
	$('div#profile_videos_holder ul li:gt('+(show-1)+')').hide();
	$('div#profile_videos_holder a.view_more').remove();
	if ($('div#profile_videos_holder ul li').size() > show) {
		$('div#profile_videos_holder ul').after('<a href="#" class="view_more">View all</a>');
	}
	$('div#profile_videos_holder a.view_more').click(function() {
		$('div#profile_videos_holder ul li:gt(1)').slideToggle();
		if ($(this).text() != 'Hide') {
			$(this).text('Hide');
		} else {
			$(this).text('View all');
		}
	});
}
function initViewProfile() {
	
	$('div#profile_gallery_holder select').change(function() { 
		var url = location.href.split('#')[0];
		$('div#profile_gallery_holder').append('<span class="loader"></span>');
		$('div#profile_gallery_holder ul').animate({opacity: '0.2'}, 10);
		$("ul#profile_gallery_list").load(url + "/get_pages/" + $(this).val(), function() {
			$('div#profile_gallery_holder span.loader').remove();
			$('div#profile_gallery_holder ul').animate({opacity: '1'}, 100);
			initViewProfileGalleryLists();
		});
	});	
	
	$('div#profile_videos_holder select').change(function() { 
		var url = location.href.split('#')[0];
		$('div#profile_videos_holder').append('<span class="loader"></span>');
		$('div#profile_videos_holder ul').animate({opacity: '0.2'}, 10);
		$("div#profile_videos_holder ul").load(url + "/get_videos/" + $(this).val(), function() {
			$('div#profile_videos_holder span.loader').remove();
			$('div#profile_videos_holder ul').animate({opacity: '1'}, 100);
			initViewProfileVideoLists();
		});
	});
	initViewProfileGalleryLists();
	initViewProfileVideoLists();
}

function initHoverable() {
	$('.hoverable').hover(
		function () {$(this).addClass('hover');}, 
		function () {$(this).removeClass("hover");}
	);
	
}


function init() {
	initHoverable();
	initMagazine();
	initViewProfile();
}


$(document).ready(init); 