var common	=	function(){
	
	// externe links
	$('a[rel="extern"]').attr('target', '_blank');

	// IE6 FIXES
	if($.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent)){
		
		$('#language').hover(function(){
			$("UL",this).addClass('active');
		}, function(){
			$("UL",this).removeClass('active');
		});
		
	}
		
		
	//	Tabs

	$("#tabs A").click(function() {
		if ($(this).attr('href').substr(0,1) == '#') {							
			$("#tabs A").removeClass('active');
			$(this).addClass('active');
			$("#tabs-content > DIV").hide();
			$($(this).attr('href')).show();
			return false;
		}
	});
	
	
	//	Actie button
	
	if ($("#actie-button").length > 0) {
		setInterval('actieButton()', 1500);	
	}
	
	
	
	// Zoeken
	
	$("#search-input").focus(function() {	
		if ($(this).val() == $(this).attr('alt')) {
			$(this).val('');
		}
	});
	$("#search-input").blur(function() {	
		if ($(this).val() == '') {
			$(this).val($(this).attr('alt'));
		}
	});
	

	$("#search-form").submit(function() {
		if ($("#search-input").val() > '') {
			location = $(this).attr('action')+base64_encode($("#search-input").val());	
		}
		return false;
	});
	
	
	
	// Formulier replacer
	
	
	
	//	Formulieren beveiligen
	
	$('<input type="hidden" name="sid" value="'+$("META[name='sid']").attr('content')+'" />').prependTo('FORM');
	
	
	//	RATEN

	$("#rating A.star").click(function() {
		var _length = $(this).parents('ul').children().length;
		var _current = $(this).parent().nextAll().length;
		var _qty = _length - _current - 1;
		
		$("#rating A.star IMG").attr('src', '/style/witlof/images/icons/star-white-normal.png');
		
		for (var i=0;i<= _qty;i++) {
			$("#rating A.star").eq(i).children('img').eq(0).attr('src', '/style/witlof/images/icons/star-white-active.png');
		}
		
		_loc = location.href.toString();
		_qty = _qty+1;
		_loc += '/rate/'+_qty;
		location = _loc;
		return false;
	});

	$("#rating A.vote").click(function() {
		var _url = $(this).attr('href');
		var _qty = $("#rating A.star IMG[src='/style/witlof/images/icons/star-white-active.png']").length;
		$(this).attr('href', _url+_qty+'/');		
	});
	
	
	//	Toon recept e-mail
	
	
	$("#content-replace-trigger").click(function() {
		$("#content-replacer").show();
		$("#content-default").hide();
		return false;
	});
	
	
	// 	Printen
	
	$(".print, .print A").click(function() {
		print();
		return false;
	});

}



//	Popup openen


var popup = function() {

	if ($("#popup").length > 0) {
		$("#popup-close, #popup-background").click(function() {
			$("#popup").remove();
			return false;
		});	
	}

	$(".popup").click(function() {
		$.get($(this).attr('href'), function(data) {
			//alert(data);
			$(data).appendTo('BODY');
			
			$('<input type="hidden" name="sid" value="'+$("META[name='sid']").attr('content')+'" />').prependTo('#popup FORM');
			
			if($.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent)) {
				$("#popup-background").css('height', $(document).height()+'px');
				
				DD_belatedPNG.fix('#popup-site, #popup-close, #popup-submit, #popup-send');
			}
			
			$("#popup-close, #popup-background").click(function() {
				$("#popup").remove();
				return false;
			});
			
			formReplace();
		});	
		return false;
	});

	
}


// FUNCTIES VOOR TRANSPARANTE PNG ONDERSTEUNING IN IE6

var pngfix	=	function(){
	
	if($.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent)) {	
		if ($("#popup-background").length > 0) {
			$("#popup-background").css('height', $(document).height()+'px');
	
		
		DD_belatedPNG.fix('.button, #content-header, #content-footer, #content-main, #menu-content UL LI, #square-left, #square-right, #language UL, #next, #previous, #square-right-recept, .print, .email, .react, .soort, .duur, .personen, #content-home, #menu-content UL LI, #rss, #popup-site, #popup-close, #popup-submit, #popup-send,.jmap-frame-top,.jmap-frame-right,.jmap-frame-bottom,.jmap-frame-left');
		
		$.pngfix('/style/default/images/common/pixel.gif');
		$('#square-left-frame,  #square-left-recept-frame').pngfix();
		}
	}
}


var gatracker = function() {	
	var GACode = $('meta[name=analytics]').attr('content');
	
	$.gaTracker(GACode, {
		external:	'/external/',
		mailto:		'/mailto/',
		download:	'/downloads/',
		extensions:	[
			'pdf','doc','xls','csv','jpg','gif', 'mp3',
			'swf','txt','ppt','zip','gz','dmg','xml'		
		]
	});
}


// FUNCTIES MET BETREKKING TOT FORMULIER, CHECKS, REPLACEMENTS, ETC

var forms	=	function(options){
		
	if(options.checkbox){
		$('input[type=checkbox]').checkbox({
			cls: 'jquery-checkbox',
			empty:'/style/default/images/common/pixel.gif'
		});
	}
	
	if(options.radio){
		$('input[type=radio]').checkbox({
			cls: 'jquery-radio',
			empty:'/style/default/images/common/pixel.gif'
		});
	}
	
	if(options.filestyle){
		$('input[type=file]').filestyle({image:'/style/witlof/images/backgrounds/winter-form-file-366.png', imageheight:27,imagewidth:100, width:266});
	}
	
	if(options.selectbox){
		$('SELECT').selectbox();		
	}
}

var video = function() {
	if ($("#video-content").length > 0) {
		$('#video-content').flash(		
			{src: 'http://st1.streamzilla.jet-stream.nl/questmedia/StreamZillaLoader.php?rtmpURL=rtmp://fl1.streamzilla.jet-stream.nl:80/VOD&amp;previewImage=http://www.zomerlof.nl/images/common/film.jpg&amp;movieName=questmedia/greenery/witlof.flv&amp;width=400&amp;height=300&amp;autoStart=0&amp;initVolume=75&amp;autoHide=1&amp;playerType=4',
			width: 400,
			height: 300, 
			flasvars: {backcolor: '0xFFFFFF',frontcolor: '0xFFFFFF',lightcolor: '0xFFFFFF',screencolor: '0xFFFFFF'}},
			{ version: 9 }
		);
	}
}

var actieButton = function() {
    var $active = $('#actie-button LI.active');

    if ( $active.length == 0 ) $active = $('#actie-button LI:last');

    var $next =  $active.next().length ? $active.next()
        : $('#actie-button LI:first');

	$active.removeClass('active');
	$next.addClass('active');
}

var formReplace = function() {
	
	$("input[type='text'], textarea").focus(function() {
		if ($(this).attr('rel') > '') {
			if ($(this).val() == $(this).attr('rel')) {
				$(this).val('');
			}
		}
	});
	$("input[type='text'], textarea").blur(function() {
		if ($(this).attr('rel') > '') {
			if ($(this).val() == '') {
				$(this).val($(this).attr('rel'));
			}
		}
	});
}


var jmaps = function() {
	
//	Google Maps
	
	if ($("#jmap").length > 0) {
		
		var markers = [];
		$("#jmap UL LI").each(function(i) {
			var _coords = $(this).attr('title');
			var _html = $(this).html();
			var _split = _coords.split(',');
			
			markers[i] = {'latitude':_split[0], 'longitude':_split[1], 'html':_html};			
		});			
			
			
		$("#jmap").jmap('init', {
			'language': 'nl',
			'mapType': 'sat',
			'mapTypes': ['sat','map','hybrid','physical'],
			'mapCenter': [51.68548778327997,4.2113471031188965],
			'mapZoom': 14,
			'mapControl': 'small',
			'mapEnableType': false,
			'mapEnableOverview': false,
			'mapEnableDragging': true,
			'mapEnableInfoWindows': true,
			'mapEnableDoubleClickZoom': true,
			'mapEnableScrollZoom': true,
			'mapEnableSmoothZoom': true,
			'mapEnableGoogleBar': false,
			'mapEnableScaleControl': false,
			'mapShowjMapsIcon': true,
			'debugMode': false
		}, function(map, element, options) {
			if (markers.length > 0) {
				for (var i=0;i<markers.length;i++) {
					$('#jmap').jmap('AddMarker', {'pointLatLng':[markers[i].latitude,markers[i].longitude], 'pointHTML':markers[i].html});				
				}
				$('#jmap').jmap('MoveTo', {'mapCenter': [markers[0].latitude,markers[0].longitude]});				
				
				$('.jmap-center').click(function() {
					var _tmp = $(this).attr('href').split(",");
					$('#jmap').jmap('MoveTo', {'mapCenter': [_tmp[0],_tmp[1]]});
					return false;
				});
			}
		});
	}		
}


common();
pngfix();
forms({selectbox:true,radio:true,checkbox:true});
formReplace();
video();
gatracker();
popup();
jmaps();
