ddsmoothmenu.init({
	mainmenuid: "smoothmenu1",
	orientation: 'h',
	classname: 'ddsmoothmenu',
	contentsource: "markup"
})

function resizeFooter()
{
	newHeight = $(window).height() - 200;
	
	if(newHeight > 400) {
		$('#footer').css('top', newHeight + 'px')
	}
}

function resizeWeb()
{
	newVertical = $(window).height() - 300;
	
	if(newVertical > 400)
	{
		$('#vertical').css('height', newVertical + 'px');
	}
	
	newHeight = $(window).height() - 200;
	
	if(newHeight > 400) {
		$('#footer').css('top', newHeight + 'px')
	}
}

$(document).ready(function(){resizeWeb()});
$(document).ready(function(){resizeFooter()});
$(document).ready(function(){
						  $("div#mio").sidebar(
							  {
								  position: "right",
									width: 350,
									height: 264,
									injectWidth:25,
									open: "click",
									close: "click"
								});
						});

$(function() {
	$(window).resize(function(){resizeWeb()});
	$(window).resize(function(){resizeFooter()});
		
	var w = $("#supersize");
	if (w.length > 0)
	{
		var items = $("#supersize a");
		if (items.length == 1)
		{
			$.fn.supersized.options = {  
				startwidth: 640,  
				startheight: 360,
				vertical_center: 1,
				slideshow: 1,
				navigation: 0,
				transition: 0, //0-None, 1-Fade, 2-slide top, 3-slide right, 4-slide bottom, 5-slide left
				pause_hover: 0,
				slide_counter: 1,
				slide_captions: 1,
				slide_interval: 5000  
			};
		}else{
			$.fn.supersized.options = {  
				startwidth: 640,  
				startheight: 360,
				vertical_center: 1,
				slideshow: 1,
				navigation: 0,
				transition: 1, //0-None, 1-Fade, 2-slide top, 3-slide right, 4-slide bottom, 5-slide left
				pause_hover: 0,
				slide_counter: 1,
				slide_captions: 1,
				slide_interval: 5000  
			};
			
			
		}
		w.supersized();
	}
	$("img.rollover").hover(
		function()
		{
			this.src = this.src.replace("_off","_on");
		},
		function()
		{
			this.src = this.src.replace("_on","_off");
		}
	);
	

	$("#Buscador").click(function(){
					$("#searchForm").submit();}
	);
	
//	$("#query").change(function(){
//	$.getJSON("/buscar/findinfo", function(data) {
//		$("#query").autocomplete(data,{
//			width: 300,
//			//multiple: false,
//			matchContains: true,
//			minChars: 2,
//			autofill: false,
//			formatItem: formatItem,
//			formatResult: formatResult
//		});
//	});
//								});
	$("#query").autocomplete("/buscar/findinfo",{
		width: 300,
		//multiple: false,
		matchContains: false,
		minChars: 3,
		autofill: false,
		formatItem: formatItem,
		formatResult: formatResult
	});
	
	
	$("#query").result(function(event, data, formatted) {
								window.location = "/producto/"+data[1]+"/"+formatted;
//		var hidden = $(this).parent().next().find(">:input");
//		hidden.val( (hidden.val() ? hidden.val() + ";" : hidden.val()) + data[1]);
	});

	
	
});

$(window).load(function(){
	var val = null;
	if($.cookie){
		val = $.cookie('listpos');
		if(val){
		  val = val.split("=");
		  if(val.length > 0){
		    val = val[1];
		  }
		}
	}
	if(val == null || isNaN(val)){
		val = 0;
	}
	$('#texto').jScrollPane({scrollbarWidth: 0, scrollbarMargin: 0, animateTo:true});

	$('.scrollContentTextWrapper').bind(
		'click',
		function()
		{
			$('#texto')[0].scrollBy(parseInt($(this).attr('rel')));
			return false;
		}
	);
	/*PAKO*/
	$('#textocatalogo2').jScrollPane({showArrows:true, scrollbarWidth: 14});
	//reposicionar seg�n la cookie
	var test = $('#textocatalogo2');
	if(val != null && !isNaN(val) && test[0]){
	  test[0].scrollTo(parseInt(val));
	}else{
	}
	
	$('#textolanzamientos').jScrollPane({scrollbarWidth: 0, scrollbarMargin: 0, animateTo:true});
		
	$('.scrollContentLanzamientosWrapper').bind(
			'click',
			function()
			{
				$('#textolanzamientos')[0].scrollBy(parseInt($(this).attr('rel')));
				return false;
			}
		);
		
	$('#textoBlancoMarcas').jScrollPane({scrollbarWidth: 0, scrollbarMargin: 0, animateTo:true});
		
	$('.scrollContentBlancoWrapper').bind(
			'click',
			function()
			{
				$('#textoBlancoMarcas')[0].scrollBy(parseInt($(this).attr('rel')));
				return false;
			}
		);
	$('#largo').css("overflow","hidden").jScrollPane({scrollbarWidth: 2, scrollbarMargin: 2, animateTo:true});
});


/** AUTOCOMPLETE **/
function formatItem(row, i , max) {
	//return row[1];// + " (<strong>id: " + row[1] + "</strong>)";
	if (row[0] == "_NO_AUTH") window.location="/usuarios/entrar";
	return row[2];
}

function formatResult(row) {
	return row[2];
	//return row[0].replace(/(<.+?>)/gi, '');
}

//********************************* EFECTO NIEVE *****************/
/*$(document).ready(function(){
	if(window.location.href == 'http://www.shinestar.es/'){
		$.getScript('/assets/snow/snowfall.min.jquery.js', function(data, textStatus){
			 $(document).snowfall({round : true, shadow : false, flakeCount:90,minSize: 2, maxSize:9});
		});	
	}
});*/
