$(document).ready(function(){
    for(count=1;count<9;count+=1)
    {
        if(!$('#nav'+count).hasClass("cur"))
        {
            $('#nav'+count+' a').hover(function(){
                $(this).parent().addClass("cur");
            },function(){
                $(this).parent().removeClass("cur");
            });
        }
    }
    $('#nav6 a').hover(function(){$('#menuOut').show()},function(){$('#menuOut').hide()});
    $('#productmenu a').click(loadproduct);

    pagelink();

    $('#productmenu2 a').click(function(){loadproduct2($(this).attr('id'));});
    llightbox();
    $('a.lightbox').lightBox({
	imageBtnClose:"/img/close.jpg",
	imageBtnPrev:"/img/Last.gif",
	imageBtnNext:"/img/Next.gif"
	});
    $('.close').click(function(){
        $(this).close();
    });
    /*$(document).bind("contextmenu",function(e){  
         return false;  
    });  */
    if( ($('.admin #catID')).length!=0 )
    {
	$('.admin #catID').load('catdrop.php?type='+$('#type').val()+'&cid='+$('#oldcatid').val(),function(){
            $('#addtemp').load('count.php?cid='+$('.admin #catID').val(),function(){
                $('#sort').val($('#addtemp').html());
            });    
        });
        
    }
    $('.admin #type').change(function(){
	$('.admin #catID').load('catdrop.php?type='+$('#type').val()+'&cid='+$('#oldcatid').val(),function(){
            $('#addtemp').load('count.php?cid='+$('.admin #catID').val(),function(){
                $('#sort').val($('#addtemp').html());
            });    
        });
    });
    $('.admin #catID').change(function(){
        $('#addtemp').load('count.php?cid='+$('.admin #catID').val(),function(){
            $('#sort').val($('#addtemp').html());
        });        
    });
    if($('#autoload').length>0)
        autoload();
});

function pagelink()
{
    $('.galery .lh:not(.njax) a').click(function(){return false;});
    $('.galery .lh:not(.njax) a').click(loadproductpage);    
}
function llightbox()
{
    $('.tb').click(function () { 
      $(this).parent().children('.frame').children('a').trigger('click');
    });
    $('.tb2').click(function () { 
      $(this).parent().parent().children('.frame').children('a').trigger('click');
    });
    $('a.lightbox2').lightBox({
        fixedNavigation:true,
	imageBtnClose:"http://canterastone.digitaldogs.com/img/close.jpg",
	imageBtnPrev:"http://canterastone.digitaldogs.com/img/Last.gif",
	imageBtnNext:"http://canterastone.digitaldogs.com/img/Next.gif"
    });
  
}

function autoload()
{
    $cid = $('#autoload').val()    
    $('#BodyText2').fadeOut(100,function(){
        $('#BodyText2').load('ajaxload.php?id='+$cid,"",function(){            
            $('#BodyText2').fadeIn('fast');
            //$('a.lightbox2').lightBox({imageBtnClose:"http://cstone.digitaldogs.com/img/close.jpg",fixedNavigation:true});
            llightbox();
    
        });
    });
}

function loadproduct()
{
    /*$('#productmenu a').removeClass("sel");
    for(count=0;count<$('#productmenu a').length;count+=1)
        $('#productmenu a').eq(count).html( ($('#productmenu a').eq(count).html()).replace(" | ","")  );
    $(this).addClass("sel");
    $(this).html(" | "+$(this).html());
    $('#BodyText2').load($(this).attr('href')+' #BodyText2',"",function(){$('#BodyText2').attr('id',"test");});
    return false;*/
    //$('#productmenu a').removeClass("sel");
    $('#productmenu a').css("color",'#705945');
    $('#productmenu a').animate({marginLeft:"2px"},50);    
    for(count=0;count<$('#productmenu a').length;count+=1)
        $('#productmenu a').eq(count).html( ($('#productmenu a').eq(count).html()).replace(" | ","")  );
    //$(this).addClass("sel");
    $(this).css('color','#495A2C');
    $(this).animate({marginLeft:"26px"},100);    
    $(this).html(" | "+$(this).html());
    //$('#BodyText2').load('ajaxload.php?name='+$(this).attr('href'),"",function(){});

    $tref = $(this).attr('href')
    $tref = $tref.replace(' ','_')
    $('#BodyText2').fadeOut(100,function(){
        $('#BodyText2').load('ajaxload.php?name='+$tref,"",function(){            
            $('#BodyText2').fadeIn('fast');
	    //$('a.lightbox2').lightBox({imageBtnClose:"http://cstone.digitaldogs.com/img/close.jpg",fixedNavigation:true});
            llightbox();
	    /*$('.lightbox2').lightBox({
		fixedNavigation:true,
		imageBtnClose:"http://cstone.digitaldogs.com/img/close.jpg",
		imageBtnPrev:"http://cstone.digitaldogs.com/img/Last.gif",
		imageBtnNext:"http://cstone.digitaldogs.com/img/Next.gif"
		});*/
            pagelink();
        });
    });
    
    
    return false;

}
function loadproductpage()
{
    $tref = $(this).attr('href')
    $tref = $tref.replace(' ','_')
    $('#BodyText2').fadeOut(100,function(){
        $('#BodyText2').load($tref,"",function(){            
            $('#BodyText2').fadeIn('fast');
            llightbox();
	    //$('a.lightbox2').lightBox({imageBtnClose:"http://cstone.digitaldogs.com/img/close.jpg",fixedNavigation:true});
	    /*$('.lightbox2').lightBox({
		fixedNavigation:true,
		imageBtnClose:"http://cstone.digitaldogs.com/img/close.jpg",
		imageBtnPrev:"http://cstone.digitaldogs.com/img/Last.gif",
		imageBtnNext:"http://cstone.digitaldogs.com/img/Next.gif"
		});*/
            pagelink();
        });
    });
}
function loadproduct2($id)
{
    $id=$id.replace('ajl','');
    location.href="/portfolio/?id="+$id;
}

function formcheck()
{
    if (document.contact.fname.value == "") 
    {
        alert("Please enter your first name.");
        document.contact.fname.focus(); 
        return false;
    }
    if (document.contact.lname.value == "") 
    {
        alert("Please enter your last name.");
        document.contact.lname.focus(); 
        return false;
    }
    if (document.contact.email.value.indexOf("@") == -1 || document.contact.email.value == "")   
    {
	alert("Please include a proper email address.");
	document.contact.email.focus(); 
	return false; 
    }
    if (document.contact.username.value == "") 
    {
        alert("Please enter a username.");
        document.contact.username.focus(); 
        return false;
    }
    if (document.contact.pass1.value == "") 
    {
        alert("Please enter a password.");
        document.contact.pass1.focus(); 
        return false;
    }
    if (document.contact.pass2.value == "") 
    {
        alert("Please enter a password.");
        document.contact.pass2.focus(); 
        return false;
    }
    if (document.contact.pass1.value != document.contact.pass2.value) 
    {
        alert("Please enter a password.");
        document.contact.pass1.focus(); 
        return false;
    }


    if(document.contact.address.value == "")
    {
	alert("Please include a street address.");
	document.contact.address.focus(); 
	return false;  	
    }
    if((document.contact.city.value == "")||document.contact.city.value.length<3)
    {
	alert("Please include a city.");
	document.contact.city.focus(); 
	return false;  		
    }
    if(document.contact.state.value.length!=2||("AL,AK,AS,AZ,AR,CA,CO,CT,DE,DC,FM,FL,GA,GU,HI,ID,IL,IN,IA,KS,KY,LA,ME,MH,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,MP,OH,OK,OR,PW,PA,PR,RI,SC,SD,TN,TX,UT,VT,VI,VA,WA,WV,WI,WY".indexOf(document.contact.state.value.toUpperCase())==-1))
    {
	alert("Please include a state code.");
	document.contact.state.focus(); 
	return false;  			
    }
    if(document.contact.country.value.length<2)
    {
	alert("Please include a country code.");
	document.contact.state.focus(); 
	return false;  			
    }
    if((document.contact.zip.value == "")||!IsNumeric(document.contact.zip.value)||document.contact.zip.value.length<5)
    {
	alert("Please include a valid zipcode.");
	document.contact.zip.focus(); 
	return false;  				
    }
    if(document.contact.phone.value == "")
    {
	alert("Please include a telephone number.");
	document.contact.phone.focus(); 
	return false;  	
    }    
    if(document.contact.used.selectedIndex == 0)
    {
	alert("Please select one.");
	document.contact.used.focus(); 
	return false;  	
    }
    if(document.contact.project.selectedIndex == 0)
    {
	alert("Please select one.");
	document.contact.project.focus(); 
	return false;  	
    }    
}

function IsNumeric(sText)
{
    var ValidChars = "0123456789";
    var IsNumber=true;
    var Char; 
    for (i = 0; i < sText.length && IsNumber == true; i++) 
    { 
        Char = sText.charAt(i); 
        if (ValidChars.indexOf(Char) == -1) 
        {
            IsNumber = false;
            //alert(Char);
        }
    }
return IsNumber;   
}

function viewpop($IID)
{
    var $w = $('#popw').val();
    var $h = $('#poph').val();
    var $left = (screen.width/2)-($w/2);
    var $top = (screen.height/2)-($h/2);
    viewwin = window.open("viewimage.php?id="+$IID,"",'channelmode=no,directories=no,fullscreen=no,height='+$h+',location=no,menubar=no,resizable=yes,scrollbar=yes;status=no,titlebar=no,toolbar=no,width='+$w+',left='+$left+',top='+$top);
    //alert()
    
}

$(window).unload(function(){
    //viewwin.window.close();
});