<!--
/*!
 **************************************************
 * Copyright 2010 - Danny Carmical
 * http://luckykind.com
 **************************************************/

var $j = jQuery.noConflict();


$j(document).ready(function() {
		var IE7 = (navigator.appVersion.indexOf("MSIE 7.")==-1) ? false : true;
	/*******************************************************
	 *
	 * Setup Featured Block Section on Homepage
	 *
	 *******************************************************/
		function setup_featured_blocks(){
			var largeBlock = $j('#featured-blocks');
			var larges = $j('#featured-main > ul > li').map(function(){ return this.id; });
			var thumbs = $j('#featured-thumbs > ul > li').map(function(){ return this.id; });
			
			$j.each(larges, function(key,value){
				if(key == 0){
					$j('#'+ value).show();
				} else {
					$j('#'+ value).hide();				
				}
			});		

			for(var i=0; i<=thumbs.length; i++) {
				if(i != 0){
					$j('#'+ thumbs[i]).show();
					} else {
					$j('#'+ thumbs[i]).hide();				
				}
			}
		}
		setup_featured_blocks();


		var larges = $j('#featured-main > ul > li').map(function(){ return $j('#' + this.id); });
		var largesDate = $j('#featured-main > ul > li').map(function(){ return $j('#' + this.id + ' > div.post-date'); });
		var largesLink = $j('#featured-main > ul > li').map(function(){ return $j('#' + this.id + ' > div > a'); });
		var largesImg = $j('#featured-main > ul > li').map(function(){ return $j('#' + this.id + ' > div > a > img'); });
		var largesDesc = $j('#featured-main .featured-desc').map(function(){ return $j('#' + this.id); });

		var thumbs = $j('#featured-thumbs > ul > li').map(function(){ return $j('#' + this.id); });
		var thumbsLink = $j('#featured-thumbs > ul > li').map(function(){ return $j('#' + this.id + ' > div > a'); });
		var thumbsSpan = $j('#featured-thumbs > ul > li').map(function(){ return $j('#' + this.id + ' > div > a > span'); });		
		var thumbsImg = $j('#featured-thumbs > ul > li').map(function(){ return $j('#' + this.id + ' > div > a > span > img'); });
		var thumbsTitle = $j('#featured-thumbs > ul > li').map(function(){ return $j('#' + this.id + ' > div > a > span > img').attr('alt'); });

		var currentKey = 0;
		var click_count = 0;

		$j.each(thumbsLink, function(key, value){
			this.bind('click', function(){
				click_count++;
				if(click_count > 1) return false;
				if(IE7) {
					switch_featured_thumb(key,currentKey);
					switch_featured_large(key,currentKey);
					switch_featured_desc(key,currentKey);					
				} else {
					$j('#tiptip_holder').fadeOut(200, function(){
						switch_featured_thumb(key,currentKey);
						switch_featured_large(key,currentKey);
						switch_featured_desc(key,currentKey);
					});					
				}
				return false;
			});			
		});

		function switch_featured_thumb(key,currentKey){
			var tempThumbLink;
			var tempThumbImg;
			var tempThumbTitle;
			var newThumbSpan;
			
			thumbsSpan[key].animate({
				opacity:0
			}, 200, function(){
				tempThumbLink = thumbsLink[key].attr('href');
				tempThumbImg = thumbsImg[key].attr('src');
				tempThumbTitle = thumbsTitle[key];
				
				thumbsTitle[key] = thumbsTitle[currentKey];
				thumbsLink[key].attr('href',thumbsLink[currentKey].attr('href'));
				thumbsImg[key].attr('alt',thumbsTitle[key]);
				thumbsImg[key].attr('src',thumbsImg[currentKey].attr('src'));
				if(thumbsImg[key].attr('src').match(/default/)) {
					thumbsSpan[key].removeClass('big-text').addClass('big-text').html("<img src=\"" + thumbsImg[key].attr('src') + "\" alt=\"" + thumbsImg[key].attr('alt') + "\" class=\"" + thumbsImg[key].attr('class') + "\" />" + thumbsTitle[key]);
				} else {
					thumbsSpan[key].removeClass('big-text').html('').html("<img src=\"" + thumbsImg[key].attr('src') + "\" alt=\"" + thumbsImg[key].attr('alt') + "\" class=\"" + thumbsImg[key].attr('class') + "\" />");
				}

				thumbsSpan[key].animate({
					opacity:1
				}, 200, function(){
					thumbsLink[currentKey].attr('href', tempThumbLink);
					thumbsImg[currentKey].attr('src', tempThumbImg);
					thumbsImg[currentKey].attr('alt', tempThumbTitle);
					thumbsTitle[currentKey] = tempThumbTitle;
					get_tip_tips();
				});
			});
		}

		function switch_featured_large(key,currentKey){
			var tempLargeLink;
			var tempLargeImg;
			var tempLargeTitle;
			var tempLargeDate;
			
			largesImg[currentKey].animate({
				opacity: 'toggle'
			}, 100, function(){
				tempLargeLink = largesLink[currentKey].attr('href');
				tempLargeImg = largesImg[currentKey].attr('src');
				tempLargeDate = largesDate[currentKey].html();

				largesDate[currentKey].html(largesDate[key].html());
				largesLink[currentKey].attr('href',largesLink[key].attr('href'));
				largesImg[currentKey].attr('alt',largesImg[key].attr('alt'));
				largesImg[currentKey].attr('src',largesImg[key].attr('src')).animate({
					opacity: 'toggle'
				}, 100, function(){
					largesDate[key].html(tempLargeDate);
					largesLink[key].attr('href', tempLargeLink);
					largesImg[key].attr('src', tempLargeImg);
					largesImg[key].attr('alt', tempLargeTitle);
				});
			});
		}

		function switch_featured_desc(key,currentKey){
			var tempLargeDesc;
			var oldPosClass = largesDesc[currentKey].attr('class');
			var newPosClass = largesDesc[key].attr('class');

			largesDesc[currentKey].animate({
				opacity:0.1
			}, 100, function(){
				tempLargeDesc = largesDesc[currentKey].html();

				largesDesc[currentKey].removeClass().addClass(newPosClass).html(largesDesc[key].html()).animate({
					opacity:1
				}, 100, function(){
					largesDesc[key].html(tempLargeDesc);
					largesDesc[key].removeClass().addClass(oldPosClass);
				});
			});
		}

		/* Modifications tipTip plugin to generate new tool tip on change ***************************************************************/
		function get_tip_tips(){
			thumbsImg = $j('#featured-thumbs > ul > li').map(function(){ return $j('#' + this.id + ' > div > a > span > img'); });
			$j.each(thumbsImg, function(key, value){
				$j(this).attr('alt',thumbsTitle[key]);
			});
			if(!IE7) {
				fire_tip_tips();
			} else {
				click_count = 0;				
			}
		}

		function fire_tip_tips() {
			thumbsImg.tipTip({
				keepAlive: false,
				edgeOffset: 0,
				attribute: 'alt'
			});							
			click_count = 0;
		}
		
		if(!IE7) {
			fire_tip_tips();

			$j('#sf-gallery img').tipTip({
				keepAlive: false,
				edgeOffset: 0,
				attribute: 'alt',
				delay: 1			
			});
		}
		
		var tweet_box = $j('#twitter-block > p');
		var tweet_user = $j('#twitter-block > p > a').attr('id');
		
		if(tweet_user!=null) {
			tweet_user = tweet_user.substr(3);
		}
		
		if(tweet_box!=null) {
			tweet_box.append('<span id="tweet-status"> - loading tweet... <img src="' + temp_dir + '/images/ajax-loader-tweet.gif" /></span>');
			$j.ajax({
			         url: temp_dir + '/library/get-tweet.php?tu=' + tweet_user,
			         cache: false,
			         type: 'GET',
			         success: function(result) {
								tweet_box.children('span').html(' ').append(' - ' + result);
			         	      }
				    });
		}
		
});

-->	
