/*--------
Product list zoom on hover
--------*/
jQuery.fn.vmrZoom = function() {
	jQuery(this).mouseover(function() {
			//Product link
			jQuery('#vmrzoom a').attr('href', jQuery(this).parent().attr('href'));
			//Product text
			jQuery('#vmrzoom .txt').html('');
			jQuery(this).parent().parent().next().clone().replaceAll('#vmrzoom .txt');
			
			//Add image to DOM
			jQuery('#vmrzoom').find('a.img').html('<img src="" />');
			
			//Product image preview
			jQuery('#vmrzoom img').attr('src', jQuery(this).attr('src'));
			
			//Overlay position
			var x = jQuery(this).offset().left - 50;
			var y = jQuery(this).offset().top - 50;
			jQuery('#vmrzoom').css('left', x+'px');
			jQuery('#vmrzoom').css('top', y+'px');
		  
			//Show overlay
			jQuery('#vmrzoom').show();
			
			//Product image final
			jQuery('#vmrzoom img').attr('src', jQuery(this).attr('rel'));
	});
	
	jQuery('#vmrzoom').mouseover(function() {
		jQuery(this).show();
	});
	
	jQuery('#vmrzoom').mouseout(function() {
		jQuery(this).hide();
		jQuery(this).find('a.img img').remove();
	});
}

jQuery(function() {
	var html = '<div id="vmrzoom" style="display: none"><a class="img" href="#"></a><div class="txt" style=""></div></div>';
	jQuery('body').append(html);
	
	jQuery('.vmrzoom').each(function() {
		jQuery(this).vmrZoom();
	});
});


/*--------
Resize content to full window height if necessary
--------*/
function resize() {
	$("div#content").css("min-height", $(window).height() - 275 - 40 - 20 - 15 - 164 - 15 - 57);
}	
$(function() { resize(); window.onresize = resize; });
/*--------
Add default prompt for input fields (defined by jQuery selector),  make it dissapear on click and reappear on blur .
Disabled, when non-default data present.
Default prompt defined in 'alt' attribute of the input field.
--------*/
function input(jQuerySelector) {
	var searchField = $(jQuerySelector);
	var searchPrompt = searchField.attr('alt');
		
	if (searchField.val() == '')
		searchField.val(searchPrompt);

	searchField.click(function() {
		if (searchField.val() == searchPrompt)
			searchField.val('');
	});
		
	searchField.blur(function() {
		if (searchField.val() == '')
			searchField.val(searchPrompt);
	});
}
/*--------
Disable submit for form (defined by jQuery selector) with empty input
--------*/
function disable_empty (jQuerySelector) {
	var searchForm = $(jQuerySelector);
	var searchField = searchForm.find('input');
	searchForm.submit(function() {
		return !(searchField.val() == '');
	});
}
/*--------
Disable submit for form (defined by jQuery selector) without a checked  radio element
--------*/
function disable_unchecked (jQuerySelector) {
	var radioForm = $(jQuerySelector);
	radioForm.submit(function() {
		if (radioForm.find('input[type=radio]').length > 0)
			return radioForm.find(":checked").length > 0;
		else
			return true;
	});
}
/*--------
Disable submit for form (defined by jQuery selector) without a checked  radio element
--------*/
$(function() { $('#ProductsIndexForm').submit(performSearch); });
function performSearch() {	
	var newAction = $('#ProductsIndexForm').attr('action') + '/index/szukaj:' + $('#ProductsSearch').val();
	$('#ProductsIndexForm').attr('action',newAction);
	return true;
}
/*--------
Support for size selector
--------*/
$(function() {
	$('#ProductSize-select').change(function() {
		if ($('#ProductSize-select').val().length != 0) {
			window.location = $('#ProductBase-url').val() + $('#ProductSize-select').val();
		}
	});
});


