$(document).ready(function ()
{
	initGallery();
	//initCustomForms();

//	if (Sys)
//		Sys.WebForms.PageRequestManager.getInstance().add_endRequest(initCustomForms);
});

function initGallery()
{
	$('.slideshow').gallery({
		autoRotation: 5000,
		listOfSlides: '.holder > ul > li'
	});
	$('.gallery').each(function ()
	{
		if ($(this).find('.brend-gallery').length)
		{
			$(this).gallery({
				listOfSlides: '.brend-gallery > .g1 > li',
				effect: 'fade'
			});
		}
		else if ($(this).find('.product-gallery').length)
		{
			$(this).gallery({
				listOfSlides: '.product-gallery > .g1 > li',
				effect: 'fade'
			});
		}
	});
}

// page init
//jQuery(function(){
//	initFadeBox();
//});

// open-close init
/*
function initFadeBox() {
	jQuery('div.fade-block').OpenClose({
		activeClass:'active',
		opener:'a.open-close',
		slider:'div.block',
		effect:'fade',
		animSpeed:500
	});
}
*/

// custom forms init
function initCustomForms()
{
	$('select.fancy').customSelect();
	$('input:radio.fancy').customRadio();
	//$('input:checkbox').customCheckbox();
}


function hideFormText() {
	var _inputs = document.getElementsByTagName('input');
	var _txt = document.getElementsByTagName('textarea');
	var _value = [];
	
	if (_inputs) {
		for(var i=0; i<_inputs.length; i++) {
			if (_inputs[i].type == 'text' || _inputs[i].type == 'password') {
				
				_inputs[i].index = i;
				_value[i] = _inputs[i].value;
				
				_inputs[i].onfocus = function(){
					if (this.value == _value[this.index])
						this.value = '';
				}
				_inputs[i].onblur = function(){
					if (this.value == '')
						this.value = _value[this.index];
				}
			}
		}
	}
	if (_txt) {
		for(var i=0; i<_txt.length; i++) {
			_txt[i].index = i;
			_value['txt'+i] = _txt[i].value;
			
			_txt[i].onfocus = function(){
				if (this.value == _value['txt'+this.index])
					this.value = '';
			}
			_txt[i].onblur = function(){
				if (this.value == '')
					this.value = _value['txt'+this.index];
			}
		}
	}
}
if (window.addEventListener)
	window.addEventListener("load", hideFormText, false);
else if (window.attachEvent)
	window.attachEvent("onload", hideFormText);

// Mini cart hover
$(document).ready(function ()
{
	//On Hover Over
	function megaHoverOver()
	{
		$(this).find("div.block").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
	}
	//On Hover Out
	function megaHoverOut()
	{
		//alert(this);
		$(this).find("div.block").stop().fadeTo('fast', 0, function ()
		{ //Fade to 0 opactiy
			$(this).hide();  //after fading, hide it
		});
	}

	//Set custom configurations
	var config = {
		sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
		interval: 100, // number = milliseconds for onMouseOver polling interval
		over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
		timeout: 300, // number = milliseconds delay before onMouseOut
		out: megaHoverOut // function = onMouseOut callback (REQUIRED)
	};

	$("#minicart div.block").css({ 'opacity': '0' }).hide();
	$("#minicart").hoverIntent(config); //Trigger Hover intent with custom configurations

	$("a.minicart-close").click(function () { $("#minicart div.block").hide(); });
});
