var _max_z_index=1;
$(document).ready(function() {
	
	window.setTimeout(function() {
		$("#loading").remove();
	},1500);
	
	
	
	$("#searchf").focus(function() {		
		if(this.value=='Search Site...') {
			this.value='';
		}
	});
	
	$("#searchf").focusout(function() {		
		if(this.value=='') {
			this.value='Search Site...';
		}
	});
	
	
	
	$("#slide_nav a").each(function(i) {
		$(this).click(function() {
			$("#slide_nav a").removeClass("current");
			$(this).addClass("current");
			if($($(this).attr('href')).css("z-index")==_max_z_index) {
				return false;
			}
			_max_z_index++;
			div_id=$(this).attr("href").substring(1);
			$("#"+div_id).hide();
			$("#"+div_id).css({zIndex:_max_z_index});
			$("#"+div_id).fadeIn(500);
			$(".slide[id!="+div_id+"]").fadeOut(500);
			$("#slides").css({height:$("#"+div_id).outerHeight()+'px'});
			
			
			return false;
		});		
	});
	$("#slide_nav a:first").triggerHandler('click');
	
	
	$("#panesnav a").each(function(i) {
		$(this).click(function() {			
			$("#panesnav a").removeClass("current");
			$(this).addClass("current");
			if($($(this).attr('href')).css("z-index")==_max_z_index) {
				return false;
			}
			_max_z_index++;
			div_id=$(this).attr("href").substring(1);
			$("#"+div_id).hide();
			$("#"+div_id).css({zIndex:_max_z_index});
			$("#"+div_id).fadeIn(500);
			$(".tabpanes[id!="+div_id+"]").fadeOut(500);
			$("#panes").css({height:$("#"+div_id).outerHeight()+'px'});


			return false;
		});		
	});
	$("#panesnav a:first").triggerHandler('click');
	
	$("#products .threecol").hover(function() {		
		$(this).addClass("active");
	},function (){
		$(this).removeClass("active");
	});
	
		$(".acccol").hover(function() {		
		$(this).addClass("active");
	},function (){
		$(this).removeClass("active");
	});
	
	
	$(".fancybox").fancybox();

	
	$("#dvd_frm").validate({
		errorClass:'error',
		showErrors: function (errorMap,errorList) {
			if(this.errorList.length>0) {				
				for ( var i = 0; this.errorList[i]; i++ ) {
					var error = this.errorList[i];
					this.settings.highlight && this.settings.highlight.call( this, error.element, this.settings.errorClass );
				}
			} else {
				for ( var i = 0, elements = this.validElements(); elements[i]; i++ ) {
					this.settings.unhighlight.call( this, elements[i], this.settings.errorClass );
				}
			}
		},
		highlight: function(element,errorClass) {
			$(element.form).find("label[for=" + element.id + "]").addClass(errorClass);
		},
		unhighlight: function(element,errorClass) {
			$(element.form).find("label[for=" + element.id + "]").removeClass(errorClass);
		}
	});
});

function dvd_submit() {

	$.ajax({
		type:'post',
		url:'/processDvdRequest.html',
		data: $("#dvd_frm").serialize(),
		dataType:'json',
		success: function (ret) {						
			if(ret.success) {
				document.location=ret.redirect
			} else {
				alert("There was an error processing your request.");
			}			
		},
		error: function (ret) {
			alert("There was an error submitting your request.");
		}
	})
}

function dvd_submit_full() {

	$.ajax({
		type:'post',
		url:'/processDvdRequestFull.html',
		data: $("#dvd_frm_full").serialize(),
		dataType:'json',
		success: function (ret) {
			if(ret.success) {
				document.location=ret.redirect
			} else {
				alert("There was an error processing your request.");
			}			
		},
		error: function (ret) {
			alert("There was an error submitting your request.");
		}
	})
}

function add_tier2_navigation(href) {
		var div=$("<div />");
		div.addClass("tier2_nav");

		$('.menu a[href="'+href+'"]+ul').each(function() {
			div.html('<ul>'+$(this).html()+'</ul>');
			$(".shadow:first").before(div);
		});
		
		$('.menu a[href="'+href+'"]:first').parent().addClass("active");
		
		$('.tier2_nav a[href="'+document.location.pathname+'"]').addClass('active');
}

function showSpecs(specifications){
   document.getElementById('lightboxwindow').innerHTML = specifications
}


function iresize(iframe) {
	try {
		iframe.style.height=(iframe.contentWindow.document.body.offsetHeight+20)+"px";
		setTimeout(function() {
			iresize(iframe)
		},1000)
	} catch(e){;}
}

function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function resizeFancy(w,h) {
	if($("#fancybox-frame").length>0) {		
		$("#fancybox-frame, #fancybox-content").css({width:w+'px',height:h+'px'});
		$.fancybox.resize();		
	}
}

function productSpec(id,evt) {	
	 if ('pageX' in evt) { // all browsers except IE before version 9
				var pageX = evt.pageX;
				var pageY = evt.pageY;
		}
		else {  // IE before version 9
				var pageX = evt.clientX + document.documentElement.scrollLeft;
				var pageY = evt.clientY + document.documentElement.scrollTop;
		}

	
	
	
	$(".product_spec_shadow").remove();
	$(".close_product_spec").remove();
	
	var div=$("<div />");
	div.html($("#"+id).html());
	div.addClass("product_spec_shadow")	
	div.attr("id","product_spec_shadow"+id);
	div.css({
		left:pageX+'px',
		top:pageY+'px',
		position:'absolute'
	});
	$("body").append(div);
	
	var img_div=$("<div />");
	img_div.addClass("close_product_spec");
	img_div.attr("id","close_product_spec"+id);
	img_div.html('<img src="/images/close.png" class="close_product_spec" />');
	img_div.css({
		left:(pageX-15)+'px',
		top:(pageY-15)+'px',
		position:'absolute',
		zIndex:'200'
	});
	
	$("body").append(img_div);
	
	$(".close_product_spec").click(function() {
		$("#product_spec_shadow"+id).remove();
		$("#close_product_spec"+id).remove();
	});
	
	
	
	
}
