// on DOM ready
$(document).ready(function (){
	$('marquee').marquee('pointer').mouseover(function () {
			$(this).trigger('stop');
		}).mouseout(function () {  
			$(this).trigger('start');
		}).mousemove(function (event) {  
			if ($(this).data('drag') == true) 
			{
				this.scrollTop = $(this).data('scrollY') + ($(this).data('y') - event.clientY);
			}
		}).mousedown(function (event) {  
			$(this).data('drag', true).data('y', event.clientY).data('scrollY', this.scrollTop);
		}).mouseup(function () {  
			$(this).data('drag', false);
		});

	if ($('#winners'))
	{
		$('#winners').innerfade({
			speed: 'slow',
			timeout: 3000,
			type: 'random'
		});	
	}
	
	$('#content2').find('table').each(function() {
		if ($(this).attr('border') == 1)
		{
			$(this).css('border', '1px solid white');
			$(this).find('td').each(function() {
				$(this).css('border', '1px solid white');
				
			});
		}
	});
	
	if ($('#photo'))
	{

		$('#photo').cycle({ fx: 'fade',
		    timeout: 10000,
		    delay:  -2000
		});	
	}
	
	swfobject.embedSWF("/banner/" + banner, "title", "1000", "141", "5.0", "/swf/expressInstall.swf");
	
	if (document.getElementById('hitlistplayer'))
	{
		$("#hitlistplayer").jPlayer({
			ready: function () {
			},
			volume: 50,
			swfPath: '/swf/',
			oggSupport: false
		})
		.jPlayerId("play", "player_play")
		.jPlayerId("pause", "player_pause")
		.jPlayerId("stop", "player_stop")
		.jPlayerId("loadBar", "player_progress_load_bar")
		.jPlayerId("playBar", "player_progress_play_bar")
		.jPlayerId("volumeMin", "player_volume_min")
		.jPlayerId("volumeMax", "player_volume_max")
		.jPlayerId("volumeBar", "player_volume_bar")
		.jPlayerId("volumeBarValue", "player_volume_bar_value")
		.onProgressChange( function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
			var myPlayedTime = new Date(playedTime);
			var ptMin = (myPlayedTime.getUTCMinutes() < 10) ? "0" + myPlayedTime.getUTCMinutes() : myPlayedTime.getUTCMinutes();
			var ptSec = (myPlayedTime.getUTCSeconds() < 10) ? "0" + myPlayedTime.getUTCSeconds() : myPlayedTime.getUTCSeconds();
			$("#play_time").text(ptMin+":"+ptSec);
	 
			var myTotalTime = new Date(totalTime);
			var ttMin = (myTotalTime.getUTCMinutes() < 10) ? "0" + myTotalTime.getUTCMinutes() : myTotalTime.getUTCMinutes();
			var ttSec = (myTotalTime.getUTCSeconds() < 10) ? "0" + myTotalTime.getUTCSeconds() : myTotalTime.getUTCSeconds();
			$("#total_time").text(ttMin+":"+ttSec);
		})
		.onSoundComplete( function() {
			$(this).play();
		});
	}
	
	if (document.getElementById('bandsplayer'))
	{
		var playItem = 0;
	 	 
		$("#bandsplayer").jPlayer({
			ready: function() {
				displayPlayList();
				playListInit(false); // Parameter is a boolean for autoplay.
			},
			swfPath: '/swf/',
			oggSupport: false
		})
		.jPlayerId("play", "player_play")
		.jPlayerId("pause", "player_pause")
		.jPlayerId("stop", "player_stop")
		.jPlayerId("loadBar", "player_progress_load_bar")
		.jPlayerId("playBar", "player_progress_play_bar")
		.jPlayerId("volumeMin", "player_volume_min")
		.jPlayerId("volumeMax", "player_volume_max")
		.jPlayerId("volumeBar", "player_volume_bar")
		.jPlayerId("volumeBarValue", "player_volume_bar_value")
		.onProgressChange( function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
			var myPlayedTime = new Date(playedTime);
			var ptMin = (myPlayedTime.getUTCMinutes() < 10) ? "0" + myPlayedTime.getUTCMinutes() : myPlayedTime.getUTCMinutes();
			var ptSec = (myPlayedTime.getUTCSeconds() < 10) ? "0" + myPlayedTime.getUTCSeconds() : myPlayedTime.getUTCSeconds();
			$("#play_time").text(ptMin+":"+ptSec);
	 
			var myTotalTime = new Date(totalTime);
			var ttMin = (myTotalTime.getUTCMinutes() < 10) ? "0" + myTotalTime.getUTCMinutes() : myTotalTime.getUTCMinutes();
			var ttSec = (myTotalTime.getUTCSeconds() < 10) ? "0" + myTotalTime.getUTCSeconds() : myTotalTime.getUTCSeconds();
			$("#total_time").text(ttMin+":"+ttSec);
		})
		.onSoundComplete( function() {
			playListNext();
		});
	 
		$("#ctrl_prev").click( function() {
			playListPrev();
			return false;
		});
	 
		$("#ctrl_next").click( function() {
			playListNext();
			return false;
		});
	 
		function displayPlayList() {
			for (i=0; i < myPlayList.length; i++) {
				$("#playlist_list ul").append("<li id='playlist_item_"+i+"'>"+ myPlayList[i].name +"</li>");
				$("#playlist_item_"+i).data( "index", i ).hover(
					function() {
						if (playItem != $(this).data("index")) {
							$(this).addClass("playlist_hover");
						}
					},
					function() {
						$(this).removeClass("playlist_hover");
					}
				).click( function() {
					var index = $(this).data("index");
					if (playItem != index) {
						playListChange( index );
					} else {
						$("#bandsplayer").play();
					}
				});
			}
		}
	 
		function playListInit(autoplay) {
			if(autoplay) {
				playListChange( playItem );
			} else {
				playListConfig( playItem );
			}
		}
	 
		function playListConfig( index ) {
			$("#playlist_item_"+playItem).removeClass("playlist_current");
			$("#playlist_item_"+index).addClass("playlist_current");
			playItem = index;
			$("#bandsplayer").setFile(myPlayList[playItem].mp3, myPlayList[playItem].ogg);
		}
	 
		function playListChange( index ) {
			playListConfig( index );
			$("#bandsplayer").play();
		}
	 
		function playListNext() {
			var index = (playItem+1 < myPlayList.length) ? playItem+1 : 0;
			playListChange( index );
		}
	 
		function playListPrev() {
			var index = (playItem-1 >= 0) ? playItem-1 : myPlayList.length-1;
			playListChange( index );
		}
	}
	
	$('#kijkje2').cycle();
	$('#spbox').cycle({ 
		fx:      'scrollHorz', 
		timeout: 6000 
	});
	
	$('#top_menu ul').superfish();
});

function initRollovers() {
    if (!document.getElementById) return

    var aPreLoad = new Array();
    var sTempSrc;
    var aImages = document.getElementsByTagName('img');

    for (var i = 0; i < aImages.length; i++) {

        if (aImages[i].className == 'imgover') {

            var src = aImages[i].getAttribute('src');
            var hsrc = aImages[i].getAttribute('hsrc');

            aPreLoad[i] = new Image();
            aPreLoad[i].src = hsrc;

            aImages[i].onmouseover = function() {
                sTempSrc = this.getAttribute('src');
                this.setAttribute('src', this.getAttribute('hsrc'));
            }

            aImages[i].onmouseout = function() {
                if (!sTempSrc) sTempSrc = this.getAttribute('dsrc');
                this.setAttribute('src', sTempSrc);
            }

        }

    }
}

var ua;

// Browser check
ua = navigator.userAgent;

var isMSIE = (navigator.appName == "Microsoft Internet Explorer");
var isMSIE5 = isMSIE && (ua.indexOf('MSIE 5') != -1);
var isMSIE6_0 = isMSIE && (ua.indexOf('MSIE 6.0') != -1);
var isMSIE7 = isMSIE && (ua.indexOf('MSIE 7') != -1);
var isMSIE8 = isMSIE && (ua.indexOf('MSIE 8') != -1);
isMSIE6_0 = (isMSIE7 || isMSIE8) ? false : isMSIE6_0;
var isGecko = ua.indexOf('Gecko') != -1; // Will also be true on Safari
var isSafari = ua.indexOf('Safari') != -1;
var isOpera = window['opera'] && opera.buildNumber ? true : false;
var isMac = ua.indexOf('Mac') != -1;
var isNS7 = ua.indexOf('Netscape/7') != -1;
var isNS71 = ua.indexOf('Netscape/7.1') != -1;

function init()
{
	var fullsize = (document.getElementById&&!document.all) ? this.innerHeight : document.documentElement.clientHeight;
	
	var n = 3;
	
	var divs=new Array(n)
	divs[0] = 'left_container';
	divs[1] = 'cel_left';
	divs[2] = 'cel';
	
	var pads = new Array(n)
	pads[0] = 0;
	pads[1] = 0;
	pads[2] = 0;

	var others = new Array(n)
	others[0] = 1178-865 + 90; // + 90
	others[1] = 1178-865;
	others[2] = 1178-865+173;
	
	var useheight = fullsize;
	for( i=0; i<n; i++) {
		useheight = Math.max(useheight, document.getElementById(divs[i]).offsetHeight + others[i]);
	}
	
	if (isMSIE6_0)
	{
		for( i=0; i<divs.length; i++) {
			document.getElementById(divs[i]).style.height = (useheight-others[i]-pads[i]/2) + 'px';
		}
	} else
	{
		for( i=0; i<divs.length; i++) {
			document.getElementById(divs[i]).style.height = (useheight-others[i]-pads[i]) + 'px';
		}
	}
} 
//

function doSearch()
{
	if (document.getElementById('zoekquery').value.length > 2)
	{
		document.getElementById('zoekform').action = '/zoeken.php';
	 	document.getElementById('zoekform').submit();
	} else
	{
		alert('Zoekterm is te kort, minimaal 3 tekens nodig');
	}
}

function submitSearch()
{
	if (document.getElementById('zoekquery').value.length > 2)
	{
		document.getElementById('zoekform').action = '/zoeken.php';
	 	return true;
	} else
	{
		alert('Zoekterm is te kort, minimaal 3 tekens nodig');
		return false;
	}
}
//

function openKaartverkoop(nummer)
{
	window.open('http://www.elmicprodukties.nl/shop/indexpopupv2.php?a_type=Agenda&a_item=' + nummer, '_blank', 'width=800, height=500, scrollbars=yes');
}

function openConcertverkoop(nummer)
{
	window.open('http://www.elmicprodukties.nl/shop/indexpopupv2.php?a_type=Festival&a_item=' + nummer, '_blank', 'width=800, height=500, scrollbars=yes');
}

function openShop(nummer)
{
	window.open('http://www.elmicprodukties.nl/shop/indexpopupv2.php?productid=' + nummer, '_blank', 'width=800, height=500, scrollbars=yes');
}

