var HOTKEY_OPENADMIN="Ctrl+k";
var HOTKEY_CLOSEADMIN="Ctrl+q";

var SITE="/";

$(document).ready(function() {

	var htkeyadmin = (HOTKEY_OPENADMIN)?HOTKEY_OPENADMIN:"Ctrl+k";
	$.hotkeys.add(htkeyadmin, function(){
		$.fn.colorbox({
			width:"980px",
			height:"80%",
			iframe:true,
			href:SITE+"backto",
			opacity: 0.6,
			onClosed: function(){
				window.location.reload();
			}
		});
	});
	
	var htkeyclose = (HOTKEY_CLOSEADMIN)?HOTKEY_CLOSEADMIN:"Ctrl+q";
	$.hotkeys.add(htkeyclose, function(){
		$.fn.colorbox.close();
	}); 

	$(".HoverView").hover(
		function(){
			var description = $(this).find("span").html();
			$(".box-description").html(description);
			$(".box-description").css("visibility","visible");
		},function(){
			$(".box-description").css("visibility","hidden");
		});

	$(".SeeComments").click(function() {
		$(this).next().slideToggle();
		return false;
	});
	

	if(window.location.href=="http://www.bodeva.com/"){
		$('#meteo').weatherfeed(['FRXX1619']);
	}
	
	$('input').click(function() {
		$('textarea').css("border","1px solid #999999");
		$('input').css("border","1px solid #999999");
  		$(this).css("border","1px solid #009dd1");
	});
	
	$('textarea').click(function() {
		$('input').css("border","1px solid #999999");
		$('textarea').css("border","1px solid #999999");
  		$(this).css("border","1px solid #009dd1");
	});
	
	$('input').focusout(function() {
		$('input').css("border","1px solid #999999");
	});
	
	$('textarea').focusout(function() {
		$('textarea').css("border","1px solid #999999");
	});

	//Set Default State of each portfolio piece
	$(".paging").show();
	$(".paging a:first").addClass("active");
		
	//Get size of images, how many there are, then determin the size of the image reel.
	var imageWidth = $(".window").width();
	var imageSum = $(".image_reel img").size();
	var imageReelWidth = imageWidth * imageSum;
	
	//Adjust the image reel to its new size
	$(".image_reel").css({'width' : imageReelWidth});
	
	//Paging + Slider Function
	rotate = function(){	
		var triggerID = $active.attr("rel") - 1; //Get number of times to slide
		var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

		$(".paging a").removeClass('active'); //Remove all active class
		$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
		
		//Slider Animation
		$(".image_reel").animate({ 
			left: -image_reelPosition,
			opacity: 0.60
		}, 500, function(){
				$(".image_reel").animate({
					opacity: 1
				});
			} );
		
	}; 
	
	//Rotation + Timing Event
	rotateSwitch = function(){		
		play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
			$active = $('.paging a.active').next();
			if ( $active.length === 0) { //If paging reaches the end...
				$active = $('.paging a:first'); //go back to first
			}
			rotate(); //Trigger the paging and slider function
		}, 7000); //Timer speed in milliseconds (3 seconds)
	};
	
	rotateSwitch(); //Run function on launch
	
	//On Hover
	$(".image_reel a").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation
	});	
	
	//On Click
	$(".paging a").click(function() {	
		$active = $(this); //Activate the clicked paging
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		rotateSwitch(); // Resume rotation
		return false; //Prevent browser jump to link anchor
	});	
	
	/*SITE INTERNET*/
	$("ul.thumb li").hover(function() {
		$(this).css({'z-index' : '10'});
		$(this).find('img').addClass("hover").stop()
			.animate({
				marginTop: '-110px', 
				marginLeft: '-110px', 
				top: '50%', 
				left: '50%', 
				width: '174px', 
				height: '174px',
				padding: '20px' 
			}, 200);
		
		} , function() {
		$(this).css({'z-index' : '0'});
		$(this).find('img').removeClass("hover").stop()
			.animate({
				marginTop: '0', 
				marginLeft: '0',
				top: '0', 
				left: '0', 
				width: '100px', 
				height: '100px', 
				padding: '5px'
			}, 400);
		});
	
		//Swap Image on Click
		$("ul.thumb li a").click(function() {
			
			var mainImage = $(this).attr("href"); //Find Image Name
			var linkImage = $(this).attr("title"); //Find link url
			$("#main_view img").attr({ src: mainImage });
			$("#main_view a").attr({ href: linkImage });
			return false;		
		});
	
	});

