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 MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  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_swapImage() { //v3.0
  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 nav(){
	$("#tp-m ul").css({display: "none"}); // Opera Fix
/*	
	$('#main-nav ul li').hover(function() {
		 $(this).find('ul:first').css({visibility: "visible",display: "none"}).slideDown(700);
	}, function() {
		 $(this).find('ul:first').slideUp(400);
	});
*/	

	$('#main-nav ul li').hover(function() {
		 $(this).find('ul:first').stop(true,true).css({visibility: "visible",display: "none"}).slideDown(700);
	}, function() {
		 $(this).find('ul:first').stop(true,true).slideUp(400);
	});



};
 
$(document).ready(function() {
	externalLinks();
	nav();
	
	$(function(){
		
		$('#main-nav li a').append('<span class="hover"></span>')
		$('#main-nav li a').hover(function() {
			// Stuff that happens when you hover on + the stop()
			$('.hover', this).stop().animate({opacity: 1}, 700,'easeOutSine')
		},function() {
			// Stuff that happens when you unhover + the stop()
			$('.hover', this).stop().animate({opacity: 0}, 700, 'easeOutQuad')
		})
	});


	$(window).scroll(function(){
		var scrollTop = $(window).scrollTop();
		if(scrollTop != 0)
			$('#btnScroll2Top').stop().animate({'opacity':'1'},400);
		else	
			$('#btnScroll2Top').stop().animate({'opacity':'0'},400);
	});

	$(".scroll2top").click(function(event){
		//prevent the default action for the click event
		event.preventDefault();

		//get the full url - like mysitecom/index.htm#home
		var full_url = this.href;

		//split the url by # and get the anchor target name - home in mysitecom/index.htm#home
		var parts = full_url.split("#");
		var trgt = parts[1];

		//get the top offset of the target anchor
		var target_offset = $("#"+trgt).offset();
		var target_top = target_offset.top;

		//goto that anchor by setting the body scroll top to anchor top
		$('html, body').animate({scrollTop:target_top}, 500);
	});

		// Start pngFix
		$(document).pngFix();
		// End pngFix



});



function validateCatsIndsForm(obj){
	if (obj.cat_id.options[obj.cat_id.selectedIndex].value != "0"){
		obj.submit();
		return true;
	}

return false;
}

function pfshowAllCats(){
	var obj = document.getElementById('select_cat');
	for (i=0; i<obj.cat_id.length; i++)
	{
		if(obj.cat_id.options[i].value=='all') {
			obj.cat_id.selectedIndex = i;
			validateCatsIndsForm(obj);
		}
	}

return false;
}

function externalLinks() {
	if (!document.getElementsByTagName) { return; }
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if ( (anchor.getAttribute("href")) &&  (anchor.getAttribute("rel")=="extlink") ) {
			anchor.target = "_blank";
		}
	}
} 
