var DEFINE = {}; 
DEFINE = function() { 
	localsettings = true;
	http_server = 'http://www.hddw.nl';
	//http_server = 'http://computer8/HDDW/local_20091118';

	return { 

		get: function(varname) { 
			 return varname;
		},
		set: function(varname, value) { 
			varname = Function(varname, 'return '+value)
		} 

	};
}();

$(document).ready(function() {	
	if ($('#banner_l_cnt').length != 0 && banner_images.length >= 2) {
		var cache_img =  $.create('div', {'id':'imgcache','style':'display:none;'}, []);
		$('body').append($(cache_img));
		$.each(
			banner_images,
			function( key, item ){
				var cache_img =  $.create('img', {'src':item['img']}, []);
				$('#imgcache').append($(cache_img));
			}
		);
	}
	
	if ($('a#plugin_toggle').length != 0) {
		$('a#plugin_toggle').click( function(e) {
			e.preventDefault();
			if ($('#plugin_space').height() == 0) {
				$('#plugin_space').animate({ 
					height: 150,
					opacity: 1
				}, 'slow' );
			} else {
				$('#plugin_space').animate({ 
					height: 0,
					opacity: 0
				}, 'slow' );
			}
			
		});
	}
	
	$('.media').media();
	
	// color arrow
	if ($('#banner_s_arrow').length != 0 && jQuery.browser.version.substr(0,3)!='1.8') {
		x = new Array(30,0,30) ; 
		y = new Array(0,50,100) ;
		
		$("#banner_s_arrow").fillPolygon(x, y, {color: '#'+definecolor}) ;
	}
		
	// tagcloud
	$('.tagcloud').each( function(i) {
		container = $(this);
		object_w = $(this).width();
		tags = new Array();
		i=0;
		$('.tag').each( function(e) {
			i = (i==0) ? 1 : 0 ;
			tag_h = $(this).html()
			tag_c = $(this).attr('class')
			tag_a = $(this).attr('href')
			tag_w = $(this).width()
			mtmp = Math.random()*((object_w - tag_w)/2)
			mleft = (i==0) ? Math.floor( mtmp ) : Math.floor( mtmp + (object_w - tag_w)/2 ) ;

			tags[e] = new Array();
			tags[e]['cnt'] = tag_h;
			tags[e]['class'] = tag_c;
			tags[e]['margin'] = mleft;
			tags[e]['href'] = tag_a;
		});
		
		container.children().remove();
		
		var destheight = 250; // hoe hoog is de cloud
		var margin = Math.round( ( ( destheight / tags.length) - 15 ) / 2 );
		
		$.each(
			tags,
			function( key, value ){
				var o = $.create('a', {'class':value['class'],'href':value['href'],'style':'margin-top:' + margin + 'px;margin-left:' + value['margin'] + 'px;'}, [ value['cnt'] ]);
				container.append($(o));
			}
		);
		
	});
		
	// banner
	if ($('#banner_l_cnt').length != 0 && banner_images.length >= 2) {
		//setup containers
		var o = $.create('div', {}, [
					$.create('div', {'id':'banner_l_img1','class':'banner_l_img'}, [
						$.create('div', {'id':'banner_l_img2','class':'banner_l_img'}, [])
					]),
					$.create('ul', {'id':'banner_l_buttons'}, [])
				]);
		
		$('#banner_l_cnt').append($(o));
		// voeg knoppen toe
		$.each(
			banner_images,
			function( key, item ){
				var o = $.create('li', {}, [ 
							$.create('a', {'class':'banner_l_a', 'href':item['url']}, [ item['title'] ]) 
						]);
				$('#banner_l_buttons').append($(o));
			}
		);
		
		// style
		dest_h = $('#banner_l_cnt').height();
		$('#banner_l_img1').css({ height:dest_h});
		$('#banner_l_img2').css({ height:dest_h, backgroundImage:'url(\'' + banner_images[0]['img'] + '\')' });
		$('#banner_l_buttons').css({height:dest_h, backgroundPosition: '0px -275px'});
		$('#banner_l_buttons').find('li:first').find('a').addClass('actief');
		
		correction = (jQuery.browser.msie==true && jQuery.browser.version=='6.0') ? 15 : 14 ;
		
		apad = Math.floor( ( ( dest_h / banner_images.length ) - correction ) / 2 )
		$('#banner_l_buttons').find('li').each (function(e) {
			$(this).children().css({'padding-top':apad,'padding-bottom':apad})
		});
		
		bt_offset_start = parseInt( $('#banner_l_buttons').css('backgroundPosition').replace('0px ','').replace('px','') );
	
		window.galleryTimeout = setTimeout(function(){change_image(0)}, 2000)
			
		function change_image(e) {
			clearTimeout(eval(galleryTimeout));
			d = (e < banner_images.length-1) ? e + 1 : 0 ;
			
			bt_offset = '0px '
			bt_offset += Math.ceil( bt_offset_start + ( ( dest_h / banner_images.length ) * d) ) - correction
			bt_offset += 'px'
			
			$('#banner_l_img2').css({'background-image':'url(\'' + banner_images[e]['img'] + '\')'})
	
			$('#banner_l_img2').fadeIn('slow', function() {
				$("#banner_l_buttons").animate({ 
					backgroundPosition:bt_offset
				}, 1500);
				$('#banner_l_img1').css({'background-image':'url(\'' + banner_images[d]['img'] + '\')'})
				$('#banner_l_img2').fadeOut('slow', function() {
					e = (e < banner_images.length-1) ? e + 1 : 0 ;
					galleryTimeout = setTimeout(function(){
						change_image(e)
					}, 3000)
				});
			});
		}
		
		$('.banner_l_a').each(function(e){
			$(this).mouseover(function(){
				clearTimeout(eval(galleryTimeout));
				
				bt_offset = '0px '
				bt_offset += Math.ceil( bt_offset_start + ( ( dest_h / banner_images.length ) * e) ) - correction
				bt_offset += 'px'
				
				$('#banner_l_img1').css( {'background-image': 'url(\'' + banner_images[e]['img'] + '\')', opacity:1} )
				$('#banner_l_img2').css( {'background-image': 'url(\'' + banner_images[e]['img'] + '\')', opacity:1} )
		
				$("#banner_l_buttons").css({ backgroundPosition:bt_offset });	
				
			}).mouseout(function(){
				galleryTimeout = setTimeout(function() {
					change_image(e)
				}, 3000);
			});
		});		
	}
	
	$('.movie_large').click( function(e){
		e.preventDefault();
		$('body').append(
			$.create('div', {'id':'movie_large_pop_cnt'}, [
				$.create('a', {'class':'movie_large_pop {width:720, height:405}'}, ['hddw promo']),
				$.create('a', {'class':'movie_large_close'}, ['close'])
			])
		);
		$('#movie_large_pop_cnt').css({
			'width' : 720,
			'height' : 405,
			'position' : 'absolute',
			'zIndex' : 999,
			'backgroundColor' : '#000000',
			'backgroundImage' : 'url(\'/images/loading.gif\')',
			'backgroundPosition' : 'center center',
			'backgroundRepeat' : 'no-repeat'
		});
		$('#movie_large_pop_cnt').css({
			'top' : ( $(window).scrollTop() + ( ($(window).height()/2) - ($('#movie_large_pop_cnt').height()/2) ) ),
			'left' : ( ($(window).width()/2) - ($('#movie_large_pop_cnt').width()/2) )
		});
		$('.movie_large_close').css({
			'float' : 'right',
			'clear' : 'both',
			'backgroundColor' : '#000000',
			'padding' : 2,
			'border' : '#FFFFFF solid 1px',
			'color' : '#FFFFFF',
			'fontWeight' : 'bold'
		}).click(function(){$(this).parent().remove();});
		$('.movie_large_pop')
		.attr({ 'href' : $(this).attr('href') })
		.css({
			'float' : 'left',
			'clear' : 'both',
			'margin' : 0
		});
		$('.movie_large_pop').media();
	});
	
});

function apply_applications_image(img,title) {
	if ($('#banner_s_cnt').length != 0) {
		$('#banner_s_cnt').css({
			'background-image':'url(\''+img+'\')'
		});
		$('#banner_s_tag span:first').html(title);
	}
}
