$(document).ready(function(){
	externalLinks();

	jQuery.fn.fadeToggle = function(speed, easing, callback) {
	  return this.animate({opacity: 'toggle'}, speed, easing, callback);  
	};

	// Add left/right classes to inline images
	$('img[align=left]').addClass('left');
	$('img[align=right]').addClass('right');

	// Logo SWF
	swfobject.embedSWF("tpl/fla/logo.1g.swf", "flash", "283", "45", "9.0.0","expressInstall.swf", 0,{wmode:'transparent'},0);

	$('p.hide a').click(function(){
		$('#body,#footer,#header ul').fadeToggle(0);
		$('#header').toggleClass('hidden');
		$('#header p.hide a').toggleClass('hidden');
		return false;
	});

	// Resize the screen so the background is always 100% height
	var offset=$('#footer').offset();
	if(offset)height=offset.top+$('#footer').height();
	if(height<$(document).height())height=$(document).height();

	$('#player,#background,#background img').height(height);
	$(window).resize(function(){$('#player,#background,#background img').height(height);});
});

function externalLinks(){
	var _a = document.getElementsByTagName('a');
	var _c = window.location.href.split('/')[2];
	for(var i=0;i<_a.length;i++){
		// Links
		if(_a[i].href.indexOf(_c)==-1&&_a[i].href.indexOf('http')==0&&_a[i].href.length>0){
			_a[i].setAttribute('target','_blank');		// target
			_a[i].className +=' ext';					// class to add icon
			if(_a[i].title.length>0){
				//_a[i].title+=" ";
			}else{
				_a[i].title=_a[i].href;
			}
			_a[i].title+=' (Opens in a new window)';	// title
		}
		// PDF files
		if(_a[i].href.indexOf('.pdf')>0&& _a[i].href.length>0){
			_a[i].setAttribute('target','_blank');		// target
			_a[i].className +=' pdf';					// class to add icon
			//if(_a[i].title.length>0) _a[i].title+=' ';
			_a[i].title+=' (PDF Document)';				// title
		}
		if(_a[i].href=='#') _a[i].href='javascript:void(0);';
	}
}
function gallery(dir){
	if(dir==1){
		$('.gallthumb').append($('.gallthumb li.on:first').removeClass('on'));
		$('.gallthumb li.on:last').next().addClass('on');
	}else{
		$('.gallthumb').prepend($('.gallthumb li.on:last').removeClass('on'));
		$('.gallthumb li.on:first').prev().addClass('on');
	}
}
function gallery_item(el){
	if($(el).length){
		var rel=$(el).attr('rel');
		if(rel=='swf'){
			$('#galleryview').html($(el).clone());
			$('#galleryview').height('296px').css({paddingBottom:'10px'});
			$('#galleryview a').css({background:'none'});
			flowplayer($(el).attr('id'),{src:"tpl/fla/flowplayer-3.1.5.swf"});
		}
		if(rel=='img'){
			var img = $('<img src="'+$(el).attr('href')+'"/>');
			img.bind('load',function(){
				$('#galleryview').height(img.height()+10);
				var offset=$('#footer').offset();
				if(offset)height=offset.top+$('#footer').height();
				if(height<$(document).height())height=$(document).height();
				$('#player,#background,#background img').height(height);

			});
			$('#galleryview').html(img);
		}
		$('#gallerycaption').html($(el).parent().find('div.comment').html());
		$(el).parent().parent().find('li.view').removeClass('view');
		$(el).parent().addClass('view');
		
	
	}
}