/* Author: 

*/

jQuery(document).ready(function($) {
	
	
	$.ajaxSetup({
	  cache: true
	});
	
	var $topTopLink = $("#toTop");
	if ($topTopLink.length > 0) {
		
		$topTopLink.click(function(){
			$('html, body').animate({scrollTop:0}, 2000);
			return false;
		});
		
	}
	
	
	
	
	
	
	
	
	var $headerImages = $("#headerImage img");
	if ($headerImages.length > 1) {
		$("#headerImage").cycle({ 
			fx:    'fade', 
			speed:  2500,
			pause: 1,
			random: 0
		 });
	}
	
	
	
	var $imageFrame = $("#content").find(".csc-frame-frame1");
	if ($imageFrame.length > 0) {
		
		var $imageLinks =  $imageFrame.find("a");
		var $newList = $('<ul></ul>');
		
		$imageLinks.each(function(index) {
			var $this = $(this),
				$img = $this.children("img"),
				imageSrc = $img.attr("src"),
				imageWidth = $img.attr("width"),
				imageHeight = $img.attr("height"),
				text = $img.attr("alt"),
				$listItem = $('<li/>');
	
			$this.empty().attr("rel","prefetch").text(text);
			
			//var tooltipContent = $("<img/>");
			//tooltipContent.bind("load", function(){alert("hello");});
			
			//tooltipContent.attr("src",imageSrc);
			
			$this.qtip({
				content: {
					title: false,
					//text: '<img src="' + imageSrc + '" width="' + $img.width() + '" height="' + $img.height() + '"/>'
					text: '<img src="' + imageSrc + '"/>'
				},
				position: {
					corner: {
						tooltip: 'bottomMiddle',
						target: 'topMiddle'
					}
				},
				style: {
					name: 'dark',
					padding: "4px",
					width: imageWidth + 10,
					height: imageHeight + 4,
					background: "#000",
					border: "#000"
				},
				adjust: {screen:true}
			});
			
			$this.appendTo($listItem);
			$listItem.appendTo($newList);
			
			var path = $this.attr("href");
			$.get(path);
		});
		
		$imageFrame.empty().append($newList);
	}
	
	
	$(window).load(function(){
		
		var $imageFrame = $("#content").find(".csc-frame-frame1");
		if ($imageFrame.length > 0) {
		
			var $imageLinks =  $imageFrame.find("a");
			$imageLinks.each(function(index) {
				
				var api = $(this).qtip("api");
				var blub;
			});
		}
	});
	
	
});





