$(document).ready(function(){

	$(".slideshow a").cycle({
		fx:'fade'
	});						   
						   
    //hover effects
    animateTopMenu("ul.lamp",300);
    animateHoverButtons(".flyinLink", 400);
	animateWorkButtons(".workLink", 400);
    animateBottomNav("ul.bottomnav", 200);

    //animateInputFields("input", 300);
    //animateInputFields("textarea", 300);

//    animateFlyinContent(".flyin-content .flyin-left", 300);
//    animateFlyinContent(".flyin-content .flyin-right", 300);

    //images
    $("a[rel^='prettyPhoto']").prettyPhoto();
    changeOpacityForImages(".imageCollection .imageFrame", 400, 0.4);

    writeMailTo(".emailToInfo", "info");
    writeMailTo(".emailToTp", "tp");
    writeMailTo(".emailToDk", "dk");
    writeMailTo(".emailToCj", "cj");
    writeMailTo(".emailToMw", "mw");
    writeMailTo(".emailToTr", "tr");
    writeMailTo(".emailToAj", "aj");

});






function writeMailTo(navigation_id, person){

    var field = $(navigation_id);

    // Email obfuscator script 2.1 by Tim Williams, University of Arizona
    // Random encryption key feature by Andrew Moulden, Site Engineering Ltd
    // This code is freeware provided these four comment lines remain intact
    // A wizard to generate this code is at http://www.jottings.com/obfuscator/
    { 

if (person == "cj"){
coded = "leKstTKt@mV.tmx"
  key = "Xbx4ErINkdQ1To5GvLRDJP8FZzjCK3yViAn2MpcfuegYhq70StB6WlwHmaUsO9"
}else if (person == "dk"){
coded = "EdZkx@3x.S3j"
  key = "NC1depoqnLBTg7AE3MKRSXbr4ztW52FHmfvZDYjIUiG6scxalOQ8uk0Vyw9JPh"
}else if (person == "tp"){
coded = "sWbGJs2@Gi.YGs"
  key = "wmJeliXnb5AOaNTZuGQ2DYEoL0BIg4pdk7Kct93Mfh16WPxVqjsRUv8CrzSFHy"
}else if (person == "info"){
coded = "Tb3l@g6.bgr"
        key = "Xj9lcnhkmsSUWHQFb4MqeJDiYPdNutKgfxTa8v5yrOC3E01w6pRAG2oVIBLZ7z"
}else if (person == "mw"){
coded = "L1WQUVGIj@rf.BrQ"
  key = "AjskJdl97ZcniEyWK5UIe0bzOhVBxpgq2PXmrtHCwG3DvYFaTM6LuQ4N1R8Sfo"
}else if (person == "aj"){
coded = "lk7Pl@Pw.GPJ"
  key = "eXY9dOqkl6EyPZTBAnrQ7ho3HbzxKGCSMNIjvFi8tfgU4pRWwD5VJm012asucL"
}else if (person == "tr"){
coded = "ExJJPJK@JP.jJE"
  key = "LjyasiEuVhDlRIrqTBKFHN0UA47SxmQ5kZpYCfXz1368dvWeGnb2wctoOMgP9J"
}


  shift=coded.length
  link=""
  for (i=0; i<coded.length; i++) {
    if (key.indexOf(coded.charAt(i))==-1) {
      ltr = coded.charAt(i)
      link += (ltr)
    }
    else {
      ltr = (key.indexOf(coded.charAt(i))-shift+key.length) % key.length
      link += (key.charAt(ltr))
    }
  }
if (person != "info"){
        $(field).html("<br/><a href='mailto:"+link+"'>"+link+"</a>");
}else{
	$(field).html("<a href='mailto:"+link+"'>"+link+"</a>");
}
    }
}

function animateFlyinContent(navigation_id, time){

    var textcolor="#111111";
    var texthighlightColor="#fff";

    $(navigation_id).hover(function(){
        $(this).children("ul").animate({
            'color' : texthighlightColor
        }, time);
    }, function(){
        $(this).children("ul").animate({
            'color' : textcolor
        }, time);
    });
}




function animateInputFields(elements, time){
    $(elements).each(function(){
        var textcolor="#222222";
        var texthighlightColor="#FFF";
        var bgColor="#fff";
        var bgHighlightColor="#CD060C";

        $(this).hover(function(){
            $(this).animate({
                'color' : texthighlightColor,
                'backgroundColor' : bgHighlightColor
            }, time);
        }, function(){
            $(this).animate({
                'backgroundColor' : bgColor,
                'color' : textcolor
            }, time);
        });

     
    });
    
    $(elements).click(function () {
        $(this).css("backgroundColor","#FFF");
    });
    $(elements).keypress(function () {
        $(this).css("backgroundColor","#FFF");
    });    
     
}

function animateHoverButtons(navigation_id, time){

    $(navigation_id).each(function(){
        $(this).hover(function(){
            $(this).css({
                'backgroundPosition': '0px 0px',
                'color':'#222222'
            }).stop().animate({
                'color': '#ffffff',
                'backgroundPosition': '-290px 0'
            }, time);
        }, function(){
            $(this).stop().animate({
                'color':'#222222',
                'backgroundPosition': '0px 0px'
            }, time);
        })

    });
}

function animateWorkButtons(navigation_id, time){

    $(navigation_id).each(function(){
        $(this).hover(function(){
            $(this).css({
                'backgroundPosition': '0px 0px',
                'color':'#ffffff'
            }).stop().animate({
                'color': '#ffffff',
                'backgroundPosition': '-600px 0'
            }, time);
        }, function(){
            $(this).stop().animate({
                'color':'#ffffff',
                'backgroundPosition': '0px 0px'
            }, time);
        })

    });
}

/*
 * animates the top menu wonderfully, when js is disabled it still works except that the current page is not highlighted
 */

function animateTopMenu(navigation_id,time){
    var list_elements=navigation_id+" li.lampLi";
    var link_elements=list_elements+" a";

    var currentPath = window.location.href;
    var currentPage=currentPath.substring(currentPath.lastIndexOf('/') + 1, currentPath.length);

var siteType = ".php";



    if (currentPage.lastIndexOf(siteType) > 0){
        currentPage = currentPage.substring(0, currentPage.lastIndexOf(siteType) + siteType.length);
    }

if (currentPage == ""){
	currentPage = "index" + siteType;
}

    $(link_elements).each(function(){

        var imagePath = 'url(css/img/nav_' + $(this).attr('id') + '.png)';
		var imagePath2 = 'url(css/img/nav_' + $(this).attr('id') + '_2' + '.png)';

            //vars used for hover
            var textcolor="#222222";
            var texthighlightColor="#FFF";
            var bgColor="#fff";
            var bgHighlightColor="#111111";
            var paddingTop=100;
            var paddingTopHighlight = 115;


        if ($(this).attr("href") != currentPage){

            //hover effect
            $(this).hover(function(){

                //change siblings opacity
                //$(this).parent().siblings("li").stop().fadeTo(1000, 0.75);
                $(this).css({
                    'backgroundImage':imagePath,
					'backgroundRepeat':'no-repeat'
                }).animate({
                    'color' : texthighlightColor,
                    'backgroundColor' : bgHighlightColor,
                    'paddingTop':paddingTopHighlight
                }, time);
            }, function(){

                //$(this).parent().siblings("li").stop().fadeTo(1000, 1);
                $(this).css({
                    'backgroundImage':''
                }).animate({
                    'color' : textcolor,
                    'backgroundColor' : bgColor,
                    'paddingTop' : paddingTop

                }, time);
            });

            
        }else{
            $(this).css({
			'paddingTop':paddingTopHighlight,
                    'backgroundImage':imagePath2,
					'backgroundRepeat':'repeat-x'
	    }).addClass("selected").animate({
			'paddingTop':paddingTop
	    }, time);
        }
    })
}

function changeOpacityForImages(navigationElement, time, opac){

    $(navigationElement).hover(function(){
        $(this).siblings("a.imageFrame").stop().fadeTo(time, opac);
    }, function(){
        $(this).siblings("a.imageFrame").stop().fadeTo(time, 1.0);
    });
}





function animateBottomNav(navigation_id,time){
    var list_elements=navigation_id+" li.bottomNavLi";
    var link_elements=list_elements+" a";

    $(link_elements).each(function(){

            //vars used for hover
	    var paddingLeft = 0;
            var paddingLeftHighlight = 15;

            //hover effect
            $(this).hover(function(){

                $(this).animate({
                    'paddingLeft':paddingLeftHighlight
                }, time);
            }, function(){

                $(this).animate({
                    'paddingLeft' : paddingLeft

                }, time);
            });

            

    })
}













