$(document).ready(function(){
	
	$('#headerimage').attr('src', BASE_URL + 'assets/images/topsection.gif')

	initMenu();
	
	$('a.foto').fancybox({
		'transitionIn'	: 'fade',
		'transitionOut'	: 'fade',
		'centerOnScroll': true
	});
	
	$("a.video").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.2-0.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 = '';
		field.style.color = '#666';
	} else if (field.value == '') {
		field.value = field.defaultValue;
		field.style.color = '#D0D0D0';
	}
}

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])
	}
}
function initMenu() {
	$('#according ul ul').hide();
	$('#according ul li a.active').closest('ul').show();
	$('#according ul li a').click(function() {
    	var checkElement = $(this).next();
    	if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
        	checkElement.slideUp('normal');
			return false;
    	}
    	if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
        	$('#according ul ul:visible').slideUp('normal');
        	checkElement.slideDown('normal');
        	return false;
		}
	});
}


function slideMessage(message, type) {
	$("<div />", {
		'class': type,
		'html': message
	})
	.hide()
	.prependTo('.infieldform fieldset')
	.slideDown('fast')
	.delay(4000)
	.slideUp(function() {
		$(this).remove(); 
	});
}
