var $j=jQuery.noConflict();
var fixColumns_kolom_arr = new Array("kolom_links","kolom_rechts");
var argus_foto_stemmen_ajax_url = ''+window.location;

$j(document).ready(argus_foto_init);

function argus_foto_init()
{
	$j("a[rel=external]").attr("target", "_blank");
	
	/*
	$j('body').onImagesLoad({
		selectorCallback: argus_foto_fixColumns_wrap
	});
	*/
	
	argus_foto_stemmen_init();
	argus_foto_themas_init();
	argus_fw_prijzen_overzicht_init();
}

function argus_foto_fixColumns_wrap()
{	
	/*console.log('fixColumns_wrap');*/
 	fixColumns(fixColumns_kolom_arr,820);
}

function argus_foto_ajax_verberg_loading_class()
{
	$j('#colorbox').removeClass('ajax_loading');
}

function argus_foto_stemmen_init()
{	
	
	// loading img tonen en verbergen tijdens ajax request
	$j(document).ajaxStart(function(){ 
		$j('#loading_popup').removeClass('hidden');
		$j('#colorbox').addClass('ajax_loading');
		$j('#loading_popup').colorbox({
				open:true, 
				inline:true, 
				href:'#loading_popup', 
				initialWidth: '160px', 
				initialHeight:'100px',
				fixedWidth: '160px', 
				fixedHeight: '100px',
				bgOpacity:0,
				overlayClose:false,
				modalClose: ''
			}); 
	});
	$j(document).ajaxStop(function(){ 
		$j('#cboxClose').click();
		$j('#loading_popup').addClass('hidden');
		setTimeout("argus_foto_ajax_verberg_loading_class()",250);
	});
	
	var lightbox_subfolder = "";
	$j('.lightbox').not('[rel]').each(function(){		
		var src = $j(this).attr('src');
		src = src.replace('beeldbank/thumbs/','beeldbank/'+lightbox_subfolder);
		src = src.replace('beeldbank/width_170/','beeldbank/'+lightbox_subfolder);
		$j(this).colorbox({href:src,bgOpacity:0.75});
	});	
	// reeksen van foto's appart inladen
	$j('.lightbox[rel=bewoners_van_de_westhoek]').each(function(){
		var src = $j(this).attr('src');		
		src = src.replace('beeldbank/thumbs/','beeldbank/'+lightbox_subfolder);
		src = src.replace('beeldbank/width_170/','beeldbank/'+lightbox_subfolder);
		$j(this).colorbox({href:src,bgOpacity:0.75, rel:'bewoners_van_de_westhoek'});
	});	
	$j('.lightbox[rel=heuvelland_in_de_westhoek]').each(function(){
		var src = $j(this).attr('src');		
		src = src.replace('beeldbank/thumbs/','beeldbank/'+lightbox_subfolder);
		src = src.replace('beeldbank/width_170/','beeldbank/'+lightbox_subfolder);
		$j(this).colorbox({href:src,bgOpacity:0.75, rel:'heuvelland_in_de_westhoek'});
	});	
	
	// stem registreren (click event)
	$j('input.stem.knop').click(function(){
		var cat_id = $j(this).attr('id').slice(13);
		var favoriet_id = $j('input[name=cat_'+cat_id+']:checked').attr('id').slice(4);
		
		/* console.log(favoriet_id);*/
		$j.post(
			argus_foto_stemmen_ajax_url, 
			{ 	'ajax': 1, 
				'method': 'argus_foto_stem_register',
				'params[1]': cat_id, 
				'params[2]': favoriet_id, 
				'params[3]': argus_foto_doelgroep 
			}, 
			function(data, textStatus){
				if (textStatus == "success")
				{
					/* console.log('#content_row_cat_'+cat_id);*/
					$j('#content_row_cat_'+cat_id+' span.argus_foto_favoriet').remove();
					$j('#thumb_item_'+favoriet_id+' div.thumb_radio').append(argus_foto_favoriet_str);
					$j('#argus_foto_stemmen_uw_keuze_wrap').html(data);
					$j('#argus_foto_stemmen_uw_keuze_wrap').onImagesLoad({
						selectorCallback: argus_foto_stemmen_uw_keuze_doen_opvallen
					});
				}
			}
		);
	});
	
	/* uw keuze widget flasht als er op link 'Overzicht van uw keuze' onderaan de pagina geklikt wordt */
	$j('.argus_foto_stemmen_uw_keuze_wrap_anker a').live('click',function(){
		setTimeout("argus_foto_stemmen_uw_keuze_doen_opvallen();",250);
	});
	
	if ($j('.argus_foto_description img[title]').length > 0)
		$j('.argus_foto_description img[title]').tooltip({effect:'slide'}).dynamic({ bottom: { direction: 'down', bounce: true, predelay: 45 } });;
}

function argus_foto_stemmen_uw_keuze_doen_opvallen()
{
	// bovenste en onderste images van blok
	$j('#argus_foto_stemmen_uw_keuze_wrap .blok_bg_img').each(function(){
		var src = $j(this).attr('src');
		var tmpsrc = src.replace(/blok_wit_smal_/, "blok_blauw_smal_");
		$j(this).attr('src',tmpsrc);
	});
	
	// class op blok zelf
	var blok = $j('#argus_foto_stemmen_uw_keuze_wrap .blok').eq(0);
	$j(blok).removeClass('wit_smal').addClass('blauw_smal');
	
	// pauze
	setTimeout("argus_foto_stemmen_uw_keuze_doen_opvallen_revert();",700);
}

function argus_foto_stemmen_uw_keuze_doen_opvallen_revert()
{
	var blok = $j('#argus_foto_stemmen_uw_keuze_wrap .blok').eq(0);
	
	// class weer goed zetten
	$j(blok).removeClass('blauw_smal').addClass('wit_smal');
	
	// bovenste en onderste images weer goed zetten
	$j('#argus_foto_stemmen_uw_keuze_wrap .blok_bg_img').each(function(){
		var src = $j(this).attr('src');
		var tmpsrc = src.replace(/blok_blauw_smal_/, "blok_wit_smal_");
		$j(this).attr('src',tmpsrc);
	});
}

function argus_foto_themas_init()
{
	if ($j('#argus_foto_themas').length > 0 && undefined == $j.getUrlParam('argus_foto_thema_show'))
	{
		$j('#argus_foto_themas').everyTime('7s','slideshow', function(i) {
		  argus_foto_thema_show(i%($j('.thema_idk').length));
		});
		$j('#argus_foto_themas').click(function(){
		  $j('#argus_foto_themas').stopTime('slideshow');
		});
	}
}
function argus_foto_thema_show(idx)
{
	$j('.thema_idk').fadeOut();
	$j('#thema_idk_'+idx).fadeIn();
}


function argus_fw_prijzen_overzicht_init()
{
	if ($j('.argus_fw_prijzen_overzicht').length > 0)
	{
		$j('.argus_fw_prijzen_overzicht .argus_fw_prijs_indeling_velden').each(function(){
			var id = $j(this).attr('id');
			$j('#'+id).everyTime('3s','slideshow', function(i) {
			  argus_fw_prijzen_overzicht_thema_show(id, i%($j('#'+id+' .thema').length));
			});
			$j('#'+id).click(function(){
			  $j('#'+id).stopTime('slideshow');
			});
		});
	}
}
function argus_fw_prijzen_overzicht_thema_show(el_id, idx)
{
	$j('#'+el_id+' .thema').fadeOut();
	$j('#'+el_id+' .thema.idx_'+idx).fadeIn();
}

