jQuery.noConflict();
jQuery(document).ready(function(){
	counter = 0;
	
	// flash inladen
	// als een div aangemaakt wordt met als class "flash",
	// en als inhoud het absolute pad naar de flash en de variable
	// wordt deze automatisch ingeladen
	jQuery('.flash').each(function(){
		slideshowvars = jQuery(this).find('.flashlink').html();
		//strip HTML comment from flash vars
		slideshowvars = slideshowvars.replace(/^<!--/, "");
		slideshowvars = slideshowvars.replace(/-->$/, "");
		slideshowheight = jQuery(this).css('height');
		slideshowwidth = jQuery(this).css('width');
		jQuery(this).html("");
		jQuery(this).flash({
	    	src: slideshowvars,
	    	width: slideshowwidth,
	    	height: slideshowheight,
			wmode: 'transparent'
		});
	});
	
	jQuery(document).pngFix().getScript('/skin/frontend/xcom/blank/js/jquery.colorbox-min.js', function() {

		//## colorbox ##
		if (typeof jQuery().colorbox == 'function')
		{

			/**
			 *	-- Gebruik --
			 *	Geef een anchor de class .js_colorbox en de href de locatie van de afbeelding
			 *	Voor een slideshow:
			 *	Geef meerdere anchor's met .js_colorbox dezelfde rel="" waarde
			 *	Voorbeeld slideshow:
			 *	<a class="js_colorbox" rel="testblaat" href="/public/img/video2.jpg">klik</a>
			 *	<a class="js_colorbox" rel="testblaat" href="/public/img/banner.jpg">klik</a>
			 */
			//set
			jQuery('.js_colorbox').colorbox({
				transition:'elastic'
			});

			/**
			* Html tonen in colorbox:
			* <a class="js_htmlcolorbox" rel="idvanjehtmldiv">Klik</a>
			*/
			jQuery('.js_htmlcolorbox').click(function(){
				var targetid = jQuery(this).attr('rel');
				if (typeof targetid == 'undefined' || targetid == '') return ;

				jQuery(this).colorbox({
					open: true,
					inline:true,
					transition:'none',
					href:"#" + targetid
				});
			});

			/**
			* Contact form tonen in colorbox:
			* Verschil met htmlcolorbox is
			* dat deze de pagina herlaadt als hij sluit
			* (om form te resetten)
			* <a class="js_contactcolorbox" rel="idvanjehtmldiv">Klik</a>
			*/
			jQuery('.js_contactcolorbox').click(function(){
				var targetid = jQuery(this).attr('rel');
				if (typeof targetid == 'undefined' || targetid == '') return ;

				jQuery(this).colorbox({
					open: true,
					inline:true,
					transition:'none',
					href:"#" + targetid,
					onClosed:function(){
						// pagina herladen
						if( typeof ajaxFormChanged != 'undefined ' && ajaxFormChanged) {
							window.location.href = window.location.href;
						}
					}
				});
			});

			/**
			* Youtube movie tonen in colorbox:
			 *	Voor een slideshow:
			 *	Geef meerdere anchor's met .colorbox dezelfde rel="" waarde
			 *	Voorbeeld slideshow:
			* <a class="js_youtubecolorbox" rel="testblaat" href="http://www.youtube.com/v/[movie-id]">Klik</a>
			*/
			jQuery('.js_youtubecolorbox').colorbox({
				iframe:true,
				innerWidth: 640,
				innerHeight:505,
				transition:'elastic'
			});
			
			jQuery('.js_colorbox_autoopen').each(function(){
				jQuery(this).colorbox({
					open: true,
					inline:true,
					transition:'none',
					href:"#"+jQuery(this).attr('id')
				});
			});
			
			jQuery('.js_colorbox_close').click(function(){
				jQuery.fn.colorbox.close();
			});
		}
    });
	
	// flash font
	jQuery('.flashfont').each(function(){
		jQuery(this).attr('id','flashfont_'+counter);
		counter ++;
		flashid = jQuery(this).attr('id');
		flashtext = encodeURIComponent(jQuery(this).html());
		flashwidth = jQuery(this).css('width');
		flashheight = jQuery(this).css('height');
		jQuery(this).html("");
		jQuery(this).flash({
	    	src: '/skin/frontend/xcom/blank/flash/flashfont.swf?textVar='+flashtext+'&amp;flashid='+flashid,
	    	width: flashwidth,
	    	height: flashheight,
			wmode: 'transparent'
		});
	});
	
	//field hints
	jQuery(".hintfield").each(function(i) {
        var beginStyle = jQuery(this).attr("style");
		jQuery(this).addClass("hint");
		jQuery(this).val(jQuery(this).attr("title"));

        jQuery(this).bind("focus", function(e) {
            if (jQuery(this).val() == jQuery(this).attr("title")) {
                jQuery(this).val("");
				jQuery(this).removeClass("hint");
            }
        });
        jQuery(this).bind("blur", function(e) {
            if (jQuery(this).val() == "") {
				jQuery(this).addClass("hint");
				jQuery(this).val(jQuery(this).attr("title"));
            } else {
				jQuery(this).css("border-color", "");
				jQuery(this).removeClass("hint");
			}
        });
    });
	
	jQuery('.ncoltable1 tr:nth-child(even)').css('background-color','#f8f8f8');
	jQuery('.ncoltable2 tr:nth-child(even)').css('background-color','#f8f8f8');
	jQuery('.ncoltable2 tr:nth-child(1)').css('background-color','#e4e4e4');
	
	
	jQuery('.ncoltable1 tr td:nth-child(2)').css('border-left','1px solid #e4e4e4');
	jQuery('.ncoltable2 tr td:nth-child(3)').css('border-left','1px solid #e4e4e4');
	
	//submit form link
	jQuery('.submitform').click(function(){
		jQuery(this).parents('form:first').submit();
	}).removeClass('submitform');

	// product compare
	jQuery('#vergelijkButton').live('click', function(){
		sel = '';

		jQuery('.item .vergelijk:checked').each(function(){
			if (0 < sel.length) sel += ',';
			sel += jQuery(this).attr('id').substr(10);
		})

		if (0 < sel.length && 'undefined' != typeof xcom_compare_session)
		{
			// use magento's (prototype) function popWin
			popWin('/catalog/product_compare/index/items/' + sel + xcom_compare_session,'compare','top:50,left:50,width=,height=,resizable=yes,scrollbars=yes');
		}
		else
		{
			alert("U dient een of meerdere producten te selecteren om te vergelijken.");
		}
	});
});

function flashFontHeight(height,id){
	jQuery('#'+id).css('height',height+'px');
	jQuery('#'+id).find('embed').attr('height',height+'px');
}
