$(document).ready(function () {
	
	$("#slider-engine ul").cycle({
		next: '#right-nav', 
		prev: '#left-nav'
	});
	
	
	 $('#temperature').weatherfeed(['USOR0207']);
	
	 
 	 $("ul.dropdown li").hover(function(){
    
        $(this).addClass("hover");
        $('ul:first',this).css('visibility', 'visible');
    
    }, function(){
    
        $(this).removeClass("hover");
        $('ul:first',this).css('visibility', 'hidden');
    
    });


	//	if ( $('#policy-link').length > 0 ) {
	  //      $("#policy-link").fancybox();
	  //  }
	
			if ( $("#flickr-images").length > 0 ) {

		        //assign your api key equal to a variable
		        var apiKey = '0930e3c29b5ab530dd7e066e74d28b42';

		        //the initial json request to flickr
		        $.getJSON('http://api.flickr.com/services/rest/?&method=flickr.photosets.getPhotos&api_key=' + apiKey + '&photoset_id=72157627024841907&format=json&jsoncallback=?',
		        function(data){

		            //loop through the results with the following function
		            $.each(data.photoset.photo, function(i,item){

		                //build the url of the photo in order to link to it
		                var photoURL = 'http://farm' + item.farm + '.static.flickr.com/' + item.server + '/' + item.id + '_' + item.secret + '_m.jpg';

		                //turn the photo id into a variable
		                var photoID = item.id;



		                    //use another ajax request to get the tags of the image
		                    $.getJSON('http://api.flickr.com/services/rest/?&method=flickr.photos.getInfo&api_key=' + apiKey + '&photo_id=' + photoID + '&format=json&jsoncallback=?',
		                    function(data){

		                        //if the image has tags
		                        if(data.photo.tags.tag != '') {

		                            //create an empty array to contain all the tags
		                            var tagsArr = new Array();

		                            //for each tag, run this function
		                            $.each(data.photo.tags.tag, function(j, item){

		                                //push each tag into the empty 'tagsArr' created above
		                                tagsArr.push('<a href="http://www.flickr.com/photos/tags/' + item._content + '">' + item.raw + '</a>');

		                            });

		                            //turn the tags array into a string variable
		                            var tags = tagsArr.join(', ');
		                        }


		                    var imgLarge = photoURL.split('m.jpg')[0] + 'b.jpg';
		                    var imgCont = '<a href="' + imgLarge + '" rel="gallery" title="' + data.photo.description._content + '"><img src="' + photoURL + '" /></a>';

		                    //append the 'imgCont' variable to the document
		                    $(imgCont).appendTo('#flickr-images'); 

		                        $("#flickr-images a").hover(
		                          function () {
		                            $(this).stop().animate({opacity: 1}, 400);
		                          },
		                          function () {
		                            $(this).stop().animate({opacity: .4}, 200);
		                          }
		                        );

		                        $("#flickr-images a").fancybox();
		                });


		          });
		        });

		    };


});


