$(function(){
	
	/* Add mouseover effect voor download images */
	if ($('img.highResImgDownloadIcon').size() > 0)
	{
		$('img.highResImgDownloadIcon').hover(
			function(){
				$(this).attr('src', '_resources/images/high-res-images-products/high_res_img_download_icon_o.png');
			}
			,
			function(){
				$(this).attr('src', '_resources/images/high-res-images-products/high_res_img_download_icon.png');
			}
		);
	}
	
	/* Add handler to productgroup selector */
	if ($('select#groupid').size() ==1)	
	{
		$('select#groupid').change(function(){ 
			window.location.href = '/press-categorie.php?groupid=' + $(this).val();
		});
	}

	
	if ($('div.fileMapDiv').size() > 0)
	{
		/* Add nomargin class to every 5th div with class fileMapDiv, waarom het -2 is weet ik, zijn er 2 div.fileMapDiv hidden of zo!? */
		$('div.fileMapDiv:nth-child(5n-2)')
			.addClass('noMargin');
	
		$('div.fileMapDiv').click(function()
		{
			var id = $(this).attr('id');			
				window.location.href = '/press-categorie.php?groupid=' + id.match(/\d+/);
		});
	}
	
	/* Add nomargin class to every 3rd div with class highResImgContainer and a div with class clear to set it to one line > werkt nog niet vlekkeloos*/
//	if ($('div.highResImgContainer').size() > 0)
//	{
//		$('div#content div.highResImgContainer:nth-child(3n)')
//			.addClass('noMargin');
//			
//		$('<div class="clear"></div>').insertAfter('div#content div.highResImgContainer:nth-child(3n)');
//	}
	
	if ($('#searchHighResImg').size() == 1)
	{
		var obj = $('#searchHighResImg')
		,	defaultValue = $(obj).val();
		
		$(obj)
			.click(function(){ 
				$(this)
					.val('')
					.focus(); 
			})
			.blur(function(){ 
				if($(this).val() == '')
				{			
					$(this).val(defaultValue != defaultSearchText? defaultValue: defaultSearchText);
				}
			});
			
		$('a#btnSubmitHighResImg')
			.click(function(){
				if ($(obj).val() != '' && $(obj).val() != defaultSearchText)
				{
					$('form#searchHighResImgForm').submit();
				}
				else
				{
					alert('Please enter a (partial) product code or name!');
				}
			});
	}
});

function openHighResImage(iid,iname)
{
	window.location = 'showproductimagelarge.php?id='+iid+'&name='+iname;
	return false;
}