/****************************************Drop Down & Rollover Menu  ********************************/
function MM_swapImgRestore() { 
  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 MM_swapImage() {
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_findObj(n, d) {
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x &&d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() {
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
	if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
	obj.visibility=v; }
}
/****************************************Drop Down & Rollover Menu ********************************/
function changehtmlcontent(htmltext){
	$('#htmlcont').html(htmltext);
}

function restorehtmlcontent(){
	$('#htmlcont').html('&nbsp;');
}
/******************* from old website **********************************/
function ValidateLogin(username, password){
if (username=="" ||  password=="" ){
    alert ("Please enter your UserName and your Password")
    return false;
}
else
{
return true;}
}

function empty(e, v){
	if (document.getElementById(e).value == v)
	{
		document.getElementById(e).value = "";	
	} 
	else {
		document.getElementById(e).select();
		 }
	document.getElementById(e).onblur = function()
	     {
	        if (document.getElementById(e).value == ""){
	            	document.getElementById(e).value = v;
	        }
	      }
 }

function ValidateSearch(txtSearch){
if (document.getElementById(txtSearch).value==""){
	alert("Please enter your search criteria");
	return false;}
	else
	return true;

}

function ValidateJoin(txtjoin){
if (document.getElementById(txtjoin).value==""){
	alert("Please enter your email");
	return false;}
	else
	return true;

}

function OpenWnd(url)
{
		wnd = window.open(url,'','height=300,width=500,status=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,top=100,left=150');
}

function SubmitLogin(btn) {
 // process only the Enter key 
 if (event.keyCode == 13) {
  // cancel the default submit 
  event.returnValue=false; 
  event.cancel = true; 
  // submit the form by programmatically clicking the specified button 
  document.getElementById(btn).click();
   } 
  }

function NewWindow(mypage, myname, w, h, scroll)
	{
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
		winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
		win = window.open(mypage, myname, winprops)
		if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
	}
	
function Reset()
	{
	    document.aspnetForm.reset();	
	}
function IsValidEmailAddress(txt) {
    if (txt.value != "") {
        var goodEmail = txt.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
        if (goodEmail) {
            return true;
        } else {
            return false;
        }
    }
}
$(document).ready(function(){
	$('.absolutemenu').hide();
});	

function showsubmenu(submenuid){
	//$('.absolutemenu').hide();
	$('a.open-acc').removeClass('open-acc');
	$(submenuid).parent().find('a:first').addClass('open-acc');
	$('.absolutemenu').slideUp();
	$(submenuid).slideToggle("slow");
}
function hidesubmenu(submenuid2){
	$(submenuid2).hide();
}

/*********************Show Footer*********************/
function showfooter(){
	
}
function scrollWin(){
	window.setTimeout(function(){$('html, body').animate({scrollTop: $("#scrollToHere").offset().top}, 2000);}, 700);
}
$(document).ready(function() {
	$("p").filter(function() { return $(this).html() == "&nbsp;" }).remove();
	//if ($("#defaultpage").length) { $('.updated-daily img').delay(3000).fadeIn(500); }
});

function fillSitemap(){
	if($('#footercontid').css('display')=='none'){
		$("#footercontid").html("<span>Loading...</span>");
		$("#footercontid").load("GetSitemap.aspx?rand=" + Math.random(), function(){
			$('#footercontid').animate({height:310}, 1300, function(){
				//alert('slide done');
				$('#footerbtn').toggleClass('showfooterbtn');
				window.setTimeout(function(){$('html, body').animate({scrollTop: $("#scrollToHere").offset().top}, 2000);}, 700);
			});
			/*alert('loaded');	*/
		});
		//alert('123')
	}else{
		$('#footercontid').animate({height:0},1300, function(){
			//alert('slide done');
			$("#footercontid").html("");
			$("#footercontid").css('display', 'none');
			$('#footerbtn').toggleClass('showfooterbtn');
		});
		//window.setTimeout(function(){$('html, body').animate({scrollTop: $("#scrollToHere").offset().top}, 2000);}, 700);
	}
}
function reloadAccordion() { window.setTimeout(function() { initMenu() }, 900); }
	// accordion ------------------------------------------

function initMenu() {
    //alert("1");
	$('.accordion li a.acc-head:first').addClass('acc-head-open');
	$('.accordion li div:first').show();
	$('.accordion li a.acc-head').click(
		function() {
			var checkElement = $(this).parent().find('div.acc-body');
			//var DivHeight = checkElement.height();
			//checkElement.css('height', DivHeight);
			if((checkElement.is('div.acc-body')) && (checkElement.is(':visible'))) {
				checkElement.slideUp(500);
				$(this).removeClass('acc-head-open');
			//return false;
			}
			if((checkElement.is('div.acc-body')) && (!checkElement.is(':visible'))) {
			$('.accordion li div.acc-body:visible').slideUp(500);
			//alert(DivHeight)
			checkElement.slideDown(500).addClass('acc-body-visible');
			$('.accordion li a.acc-head').removeClass('acc-head-open');
			$(this).addClass('acc-head-open');
			return false;
		}
	});
}

function scrollToIt(list) {
    var newPage = list.options[list.selectedIndex].value
    if (newPage != "None") {
       $('html, body').animate({ scrollTop: $("#" + newPage).offset().top }, 2000);
    }
}
function backToTop() {
 $('html, body').animate({ scrollTop: $("#top").offset().top }, 2000);
}
/*___________________________________________TO ADD________________________________*/
/*_____________________________FADE___________________________________*/
$(document).ready(function(){				
//Change image when thumbnail is clicked
	var i = 1
	$('#itemlist ul li').each(function(){
		$(this).attr('id', i + 1);
		i = i+1;
	});
	var originalimage = $('#itemlist ul li:first a').attr("href");
	$('#itemlist ul li:first a img').addClass('on');
	//alert(originalimage);
	$('#gal_image').attr('src', originalimage);
	$("#itemlist ul li a img").hover(function () {
		$(this).stop().fadeTo(1000,1);
		},
		function() {
		$(this).stop().fadeTo(700,0.7);
	});
	
	
	$('#itemlist ul li a').click(function(ev){
		$(this).find('img').fadeTo(1000,1);
		$('#itemlist ul li a img.on').removeClass('on');
		$(this).find('img').mouseout().addClass('on');
		//$(this).find('img').mouseOut().css('filter', 'alpha(opacity=100)');
		ev.preventDefault();
		var imgLink = $(this).attr("href");
		
		$('#gal_image').fadeOut('medium',function(){						
		$('#gal_image').load(function(){
		$(this).fadeIn();
		}).attr('src', imgLink);
		});
	});		
});
/*________________________________________________________________*/

$(document).ready(function() {
    commentsbg();
});

function commentsbg(){
	$('.comments-bg:odd').css('background-color', 'white');
}
function Get360view(id, DivID) {
    $("#" + DivID).show("normal");
   $("#" + DivID).html("<span>Loading...</span>");
   var strflash = "";
   var DivID2 = "'" + DivID + "'";
   strflash = "<div class='flashdiv'><div><object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='430' height='330' title='ProductFlash'>";
   strflash += "<param name='movie' value='Library/Products/360/" + id + "' /><param name='quality' value='high' /><param name='wmode' value='transparent' />";
   strflash += "<embed src='Library/Products/360/" + id + "' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='430' height='330' wmode='transparent'></embed></object></div>";
   strflash += "<div align='center'><a style='color:#FFF' href=javascript:CloseDiv(" + DivID2 + ")>Close</a><br><Br></div></div>";
    $("#" + DivID).html(strflash);
}
function CloseDiv(DivID) { $("#" + DivID).fadeOut("normal"); }

function openCompare(url) {
    //var randStr = '&n=' + (Math.floor(Math.random() * 9999999999999999999999));
    $("<a>").appendTo("body").attr("href", url).colorbox({ open: true }).remove();
}
function checkCompare() {
    var strIDs = "";
    var allElements = $(".chkcomp:checked");
    if (allElements.length == 2) {
        for (var curElement = 0; curElement < allElements.length; curElement++) {
            if (curElement == 0) {
                strIDs += "P1=" + allElements[curElement].value;
            } else {
                strIDs += "&P2=" + allElements[curElement].value;
            }
        }
        // alert(strIDs);
        openCompare('GetCompare.aspx?' + strIDs);
    }
}
function ValidateOtherSearch(source, args) {
    var keyword = $('.searchfield').val();
    if (keyword == "" || keyword.length < 2)
            args.IsValid = false;
        else
            args.IsValid = true;
}

/*_________________________________________________________________*/
	function breadcrumbs(pageTitle, pageLink){
		var writeLink = '<a href="default.aspx">Home</a> &gt; <a href="' + pageLink + '.aspx" class="selected">' + pageTitle
		//alert (writeLink);
		$('.breadcrumbs').html(writeLink);
	}
	
$(document).ready(function(){	
	//$('.other-products-item').parent().hover(function(){
		//$(this).toggleClass('grey-bg')													  
	//});
	$('#footersubscribebtn').click(function(){
		$('#footersubscribe').slideToggle();
	})

	$('#closebtn').click(function(){
		$('#footersubscribe').slideToggle();
	})
});

/******************************************************************Load Submenu****************************************/
//$(document).ready(function(){	
//	var randStr = '?n='+(Math.floor(Math.random()*9999999999999999999999));
//	$(document).load('GetSubCategories.aspx'+randStr, function(e){
//		$('.dock-container a').click(function(){
//			var requestedDiv = $(this).attr('name')
//			var requestedHtml = $(e).find('div[name='+requestedDiv+']').html()
//			//alert(requestedHtml)
//			if($('.sublevel-menu-links').height()=='0'){
//				$('.sublevel-menu-links').animate({height:30}, function(){
//					$('.sublevel-menu-links-inner').empty().hide()
//					$('.sublevel-menu-links-inner').html(requestedHtml).fadeIn();
//				})
//			}else{
//				//alert($('.sublevel-menu-links').height())
//					$('.sublevel-menu-links-inner').empty().hide()
//					$('.sublevel-menu-links-inner').html(requestedHtml).fadeIn();
//				}
//		})
//	})
//})

function loadSubCats(catid,currentid) {
    var randStr = '&n=' + (Math.floor(Math.random() * 9999999999999999999999));
   // $(document).load('GetSubCategories.aspx?ID=' + catid + randStr, function(e) {
        //$('.dock-container a').click(function() {
    //var requestedDiv = $(this).attr('name')

    $.get('GetSubCategories.aspx?CatID=' + currentid + ' &ID=' + catid + randStr, '', function(data) {
        if ($('.sublevel-menu-links').height() == '0') {
            $('.sublevel-menu-links').animate({ height: 30 }, function() {
                $('.sublevel-menu-links-inner').empty().hide()
                $('.sublevel-menu-links-inner').html(data).fadeIn();
            })
        } else {
            //alert($('.sublevel-menu-links').height())
            $('.sublevel-menu-links-inner').empty().hide()
            $('.sublevel-menu-links-inner').html(data).fadeIn();
        }
    
    });
      
        // })
   // })

}



/********************************Homepage function*****************************/
function itemsPositionning(){
	var itemIndex = $(this).index('.item-holder');
	$('.item-holder').each(function(){
		$(this).css('top', itemIndex+308+'px')
	})	
}


$(document).ready(function(){
	$('.closecontentbtn').click(function(){
		//alert('test');
		$('.item-holder a.active').animate(
			{backgroundPosition:"(-175px 0)"}, 
			{duration:200})
		$('.floated-content-holder').fadeOut(500, function(){
			$('.items-holder-column:eq(0)').animate({left: '0'}, 500, function(){
				$('#wowslider-container1').fadeIn(500)
			});
			$('.items-holder-column:eq(1)').animate({left: '182px'}, 500);
			$('.items-holder-column:eq(2)').animate({left: '364px'}, 500);
		})
	})
})

function applysameHeight(elem){
	var tallest = 0;
	$(elem).each(function(){
	if (tallest < $(this).height()) { tallest = $(this).height(); }
	//alert(tallest);
	});
	$(elem).css({'height': tallest});
}
function applysameHeight2(elem2){
	var tallest2 = 0;
	$(elem2).each(function(){
	if (tallest2 < $(this).height()) { tallest2 = $(this).height(); }
	//alert(tallest);
	});
	$(elem2).css({'height': tallest2});
}

function loadContent(pageToLoad){
	var randStr = 'n='+(Math.floor(Math.random()*9999999999999999999999));
	if(pageToLoad.indexOf("?") != -1){
		randStr = "&"+randStr;
	} else {
		randStr = "?"+randStr;
	}
	
	$('#loadContent').load(pageToLoad+randStr, function(){
		$('#loadContent').fadeIn(1500);
		$('#loadContent').imagesLoaded(function() {
			applysameHeight('.content-table-image')
			applysameHeight2('h2')
		});
	});
}


function showContent(pageToLoad, clickedItem){
	$('#wowslider-container1').fadeOut(500)
	//alert(clickedItem)
	var clickedItemParentIndex = $(clickedItem).parents('.items-holder-column').index()
	//alert($('.floated-content-holder eq:('+clickedItemParentIndex+')').css('display'))
	setTimeout(function(){
		if ($('.floated-content-holder').css('display') == 'block'){
			$('#loadContent').empty();
			//alert('div already open');
			if(clickedItemParentIndex==0){
				$('.floated-content-holder').animate({left: '180px'}, 500, function(){
					loadContent(pageToLoad);
				});
				$('.items-holder-column:eq(0)').animate({left: '0'}, 500);
				$('.items-holder-column:eq(1)').animate({left: '613px'}, 500);
				$('.items-holder-column:eq(2)').animate({left: '794px'}, 500);
			}else if(clickedItemParentIndex==1){
				$('.floated-content-holder').animate({left: '362px'}, 500, function(){
					loadContent(pageToLoad);
				});
				$('.items-holder-column:eq(0)').animate({left: '0'}, 500);
				$('.items-holder-column:eq(1)').animate({left: '182px'}, 500);
				$('.items-holder-column:eq(2)').animate({left: '794px'}, 500);
			}else if(clickedItemParentIndex==2){
				$('.floated-content-holder').animate({left: '544px'}, 500, function(){
					loadContent(pageToLoad);
				});
				$('.items-holder-column:eq(0)').animate({left: '0'}, 500);
				$('.items-holder-column:eq(1)').animate({left: '182px'}, 500);
				$('.items-holder-column:eq(2)').animate({left: '364px'}, 500);
			}
		}else{
			$('#loadContent').empty();
			//alert(clickedItemParentIndex)
			$('.floated-content-holder').css('left', (clickedItemParentIndex+1)*180+'px').fadeIn(500);
			if(clickedItemParentIndex==0){
				$('.items-holder-column:eq(0)').animate({left: '0'}, 500, function(){
					loadContent(pageToLoad);
				});
				$('.items-holder-column:eq(1)').animate({left: '613px'}, 500);
				$('.items-holder-column:eq(2)').animate({left: '794px'}, 500);
			}else if(clickedItemParentIndex==1){
				$('.items-holder-column:eq(0)').animate({left: '0'}, 500, function(){
					loadContent(pageToLoad);
				});
				$('.items-holder-column:eq(1)').animate({left: '182px'}, 500);
				$('.items-holder-column:eq(2)').animate({left: '794px'}, 500);
			}else if(clickedItemParentIndex==2){
				$('.items-holder-column:eq(0)').animate({left: '0'}, 500, function(){
					loadContent(pageToLoad);
				});
				$('.items-holder-column:eq(1)').animate({left: '182px'}, 500);
				$('.items-holder-column:eq(2)').animate({left: '364px'}, 500);
			}
		}
		//alert(clickedItemParentIndex)
	}, 200)
	
}

//set animation speed
var delayspeed = 500
function showItems(){
	//alert(itemCount)
	$('.item-holder').each(function(){
		//set the position where each should be positioned
		var itemIndex = ($(this).index('.item-holder'))+1;
		var itemIndexInParent = ($(this).index());
		var parentIndex = ($(this).parent().index())+1
		//alert(itemIndex)
		var itemTopPosition = (itemIndexInParent)*50
		$(this).delay(itemIndex*200).animate({top:itemTopPosition+4+'px'}, 1000)
		//alert(itemIndex);
	})
}


function animateColumns(){
	var itemCount = $('.items-holder-column').length;
	setTimeout(function(){
		showItems();
	}, itemCount*delayspeed)
	$('.items-holder-column').each(function(){
		var indexOfThis = $(this).index('.items-holder-column')
		//alert(indexOfThis);
		$(this).delay(indexOfThis*delayspeed).animate({top:0}, 1000)
	})
	//alert(itemCount)
}

/********************************Homepage function*****************************/



