$(document).ready(function(){

	$(".fg-button:not(.ui-state-disabled)")
	.hover(
		function(){ 
			$(this).addClass("ui-state-hover"); 
		},
		function(){ 
			$(this).removeClass("ui-state-hover"); 
		}
	)

	$('a.foto').fancybox({
		'transitionIn'	: 'fade',
		'transitionOut'	: 'fade',
		'centerOnScroll': true
	});
		
	$('a.pdf').media({width:630, height:500});
	
	$("a.audio").each(function(i) {

		$(this).after('<div id="audio'+i+'" class="audiowrap"></div>');
		
		$f("audio"+i, BASE_URL + 'assets/js/flowplayer/flowplayer-3.2.7.swf', {
			// fullscreen button not needed here
			plugins: {
				controls: {
					fullscreen: false,
					height: 25,
					autoHide: false
				}
			},
			clip: {
				url: $(this).attr('href'),
				autoPlay: false,
		
				// optional: when playback starts close the first audio playback
				onBeforeBegin: function() {
					$f("player").close();
				}
			}
		
		});
		
	});
	
	$("a.video").each(function(i) {

		$(this).after('<div id="player_'+i+'" class="videowrap"></div>');
		
		flowplayer("player_"+i, BASE_URL + 'assets/js/flowplayer/flowplayer-3.2.7.swf', {
			play:{opacity:0},
			clip: {
				autoBuffering: true,
				url: $(this).attr('href'),
				autoPlay: false
			}
		});
		
	});
	
	$("a.videobox").click(function() {
		var videoclip;
		videoclip = $(this).attr('href');
		$.fancybox({
				'width'			: 640,
				'height'		: 480,
				'autoScale'		: true,
				'transitionIn'	: 'fade',
				'transitionOut'	: 'fade',
				'centerOnScroll': true,
				'type'			: 'swf',
				'swf'			: {
					'wmode'		: 'transparent',
					'allowfullscreen'	: 'true'
				},
				'onStart'	: function() {
					player = flowplayer( 'fancybox-content', BASE_URL + 'assets/js/flowplayer/flowplayer-3.2.7.swf', {
						play:{opacity:0},

						clip:{					
							url: videoclip,
        					autoBuffering: true,
							autoPlay: true
						}
					});	

				},
				'onComplete' : function() {
					player.load();
				}
		});
		return false;
	});
	
	$('a.youtube_thumb').each(function(){
		url = $.jYoutube($(this).attr('href'), 'small');
		 $(this).html($('<img src="'+url+'" />'));
	});
	$("a.youtube").click(function() {
		$.fancybox({
				'padding'		: 0,
				'autoScale'		: false,
				'transitionIn'	: 'none',
				'transitionOut'	: 'none',
				'title'			: this.title,
				'width'			: 680,
				'height'		: 495,
				'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
				'type'			: 'swf',
				'swf'			: {
					 'wmode'		: 'transparent',
					'allowfullscreen'	: 'true'
				}
			});
	
		return false;
	});
});

function clearText(field)
{
    if (field.defaultValue == field.value) {		
		field.value = '';
	} else if (field.value == '') {
		field.value = field.defaultValue;
	}
}

function loadjscssfile(filename, filetype){
	if (filetype=="js"){
		var fileref=document.createElement('script')
		fileref.setAttribute("type","text/javascript")
		fileref.setAttribute("src", filename)
	}
	else if (filetype=="css"){
		var fileref=document.createElement("link")
		fileref.setAttribute("rel", "stylesheet")
		fileref.setAttribute("type", "text/css")
		fileref.setAttribute("href", filename)
	}
	if (typeof fileref!="undefined")
	document.getElementsByTagName("head")[0].appendChild(fileref)
}

function removejscssfile(filename, filetype){
	var targetelement=(filetype=="js")? "script" : (filetype=="css")? "link" : "none"
	var targetattr=(filetype=="js")? "src" : (filetype=="css")? "href" : "none"
	var allsuspects=document.getElementsByTagName(targetelement)
	for (var i=allsuspects.length; i>=0; i--){
		if (allsuspects[i] && allsuspects[i].getAttribute(targetattr)!=null && allsuspects[i].getAttribute(targetattr).indexOf(filename)!=-1)
			allsuspects[i].parentNode.removeChild(allsuspects[i])
	}
}

