<!--
/*!
 **************************************************
 * 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;
			
		function setup_featured_video_images(){
			var lightBoxVideos = $j('a.lightbox-medium-frontpage');
			$j.each(lightBoxVideos,function(){

				$j(this).hover(
					function(){
						$j(this).children().stop().animate({
							opacity:0.2
						},500);
					},
					function(){
						$j(this).children().stop().animate({
							opacity:1
						},500);				
					}
				);
			});
		}
		
		function setup_buttons(){
			var pageButtons = $j('a.tg-lurgan-icon');
			$j.each(pageButtons,function(){
				$j(this).hover(
					function(){
						$j(this).children().stop().animate({
							opacity:0
						},100);
					},
					function(){
						$j(this).children().stop().animate({
							opacity:1
						},100);				
					}
				);
			});
			}
			setup_buttons();
		
		function setup_lightbox_images() {
			//alert("setting up lightbox images");
			var lightBoxImages = $j('a.lightbox');
			$j.each(lightBoxImages,function(){			
		
			$j(this).colorbox({iframe:true,innerWidth:830, innerHeight:690});

		});
			
		}
		setup_lightbox_images();
		setup_featured_video_images();
		
	/*******************************************************
	 *
	 * 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.large-link'); });
		var readMoreLink = $j('#featured-main > ul > li').map(function(){ return $j('#' + this.id + ' > div > a.read-more'); });
		var largesImg = $j('#featured-main > ul > li').map(function(){ return $j('#' + this.id + ' > div > a > span'); });
		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];
				//alert("Old : " + tempThumbTitle);
				thumbsTitle[key] = thumbsTitle[currentKey];
				thumbsLink[key].attr('href',thumbsLink[currentKey].attr('href'));
				thumbsImg[key].attr('alt',thumbsTitle[key]);
				//alert("New : " + 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){
			//alert(largesImg[currentKey].html());
			//alert(largesImg[key].html());
			//alert(largesImg[currentKey].children().attr('src',largesImg[key].children().attr('src')));
			var tempLargeLink;
			var tempLargeLinkClass;
			var tempLargeLinkTarget;
			var tempLargeImg;
			var tempLargeTitle;
			var tempLargeDate;
			var tempReadMoreLink;
			
			largesImg[currentKey].animate({
				opacity: 'toggle'
			}, 100, function(){
				tempLargeLink = largesLink[currentKey].attr('href');
				tempLargeLinkClass = largesLink[currentKey].attr('class');
				tempLargeLinkTarget = largesLink[currentKey].attr('target');
				tempLargeImg = largesImg[currentKey].html();
				tempLargeDate = largesDate[currentKey].html();
				tempReadMoreLink = readMoreLink[currentKey].attr('href');
				//alert("Old : " + tempLargeLink);
				largesDate[currentKey].html(largesDate[key].html());
				largesLink[currentKey].attr('href',largesLink[key].attr('href'));
				largesLink[currentKey].attr('class',largesLink[key].attr('class'));
				largesLink[currentKey].attr('target',largesLink[key].attr('target'));
				readMoreLink[currentKey].attr('href',readMoreLink[key].attr('href'));
				//largesImg[currentKey].attr('alt',largesImg[key].attr('alt'));
				largesImg[currentKey].html(largesImg[key].html()).animate({
					opacity: 'toggle'
				}, 100, function(){
					largesDate[key].html(tempLargeDate);
					largesLink[key].attr('href', tempLargeLink);
					largesLink[key].attr('class', tempLargeLinkClass);
					largesLink[key].attr('target', tempLargeLinkTarget);
					largesImg[key].html(tempLargeImg);
					readMoreLink[key].attr('href', tempReadMoreLink);
					//alert("New : " + largesLink[key].attr('href'));
					//largesImg[key].attr('alt', tempLargeTitle);
					setup_lightbox_images();
				});
			});
			
		}

		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(' - ' + result);
			         	      }
				    });
		}
		
});

-->	
