// JavaScript Document

$(function() {

// to test that the external file is being accessed
	$('#darren').click(function(event) {
		alert("The external file works!")
	});


// GOOGLE ANALYTICS
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-21610653-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
	

// MARKETSITE SLIDES
	$('#marketsiteSlides').slides({
		preload: true,
		preloadImage: 'img/slideshow/loading.gif',
		play: 3000,
		pause: 3000,
		hoverPause: true,
		//generateNextPrev: true
	});
	
	
// TABS AREA
	// tabs will work on the slideshow...


// PARTNERS SLIDES
	$('#partnersSlides').slides({
		preload: true,
		preloadImage: 'img/slideshow/loading.gif',
		play: 3000,
		pause: 3000,
		hoverPause: true,
		effect: 'fade'
	});


// MAIN ROTATION
	$rotation = {
		context: false,
		tabs: false,
		timeout: 4500,  
		slideSpeed: 1500,
		tabSpeed: 1000,
		fx: 'fade', 
		
		init: function() {
			this.context = $('#rotation');
			this.tabs = $('ul.slides-nav li', this.context);
			this.tabs.remove();
			this.preparerotation();
		},
	
		preparerotation: function() {
			$('div.slides > ul', $rotation.context).cycle({
				fx: $rotation.fx,
				timeout: $rotation.timeout,
				speed: $rotation.slideSpeed,
				fastOnEvent: $rotation.tabSpeed,
				pager: $('ul.slides-nav', $rotation.context),
				pagerAnchorBuilder: $rotation.prepareTabs,
				before: $rotation.activateTab,
				pauseOnPagerHover: true,
				pause: true
			});            
		},
    
		prepareTabs: function(i, slide) {
			return $rotation.tabs.eq(i);
		},

		activateTab: function(currentSlide, nextSlide) {
			var activeTab = $('a[href="#' + nextSlide.id + '"]', $rotation.context);
			if(activeTab.length) {
				$rotation.tabs.removeClass('on');
				activeTab.parent().addClass('on');
			}            
		}            
	};

	$(function() {
		$('body').addClass('js');
		$rotation.init();
	});  


// DIV BOX
	$('a.lightbox1').divbox();
	
	//$('a.gallery').divbox();


// IMPORT XML

		$.get('ajax-content/reuters_news.xml', function(theFeed){
			var container = document.getElementById("feed");
			$(theFeed).find('Headline').each(function(){
				var $headline = $(this);
				var title = $headline.find('Title').text();
				var date = $headline.find('Date').text();
				//var source = $headline.find('Source').text();
				
				var html = '<dt>' + title + '</dt>';
				html += '<dd>' + date + '</dd>';
				
				$("#feed").append($(html));
				//alert(title);
			});
		});
		
// Financial xml
	$.get('ajax-content/merc_fin.xml', function(finTable){
		var container = document.getElementById("table_fin");
		$(finTable).find('cd').each(function(){
			var $cd = $(this);
			var theTitle = $cd.find('name').text();
			var theUnit = $cd.find('unit').text();
			var thePrice = $cd.find('price').text();

			var html = '<tr><td>' + theTitle + '</td>';
			html += '<td>' + theUnit + '</td>';
			html += '<td class="change">' + thePrice + '</td></tr>';
			
			$("#table_fin").append($(html));
			//alert(title);
		});
	});
		


// NEXT	
	$tabArea = {
		context: false,
		tabs: false,
		timeout: 4500,  
		slideSpeed: 1500,
		tabSpeed: 1000,
		fx: 'fade', 
		
		init: function() {
			this.context = $('#rotation');
			this.tabs = $('ul.slides-nav li', this.context);
			this.tabs.remove();
			this.preparerotation();
		},
	
		preparerotation: function() {
			$('div.slides > ul', $rotation.context).cycle({
				fx: $rotation.fx,
				timeout: $rotation.timeout,
				speed: $rotation.slideSpeed,
				fastOnEvent: $rotation.tabSpeed,
				pager: $('ul.slides-nav', $rotation.context),
				pagerAnchorBuilder: $rotation.prepareTabs,
				before: $rotation.activateTab,
				pauseOnPagerHover: true,
				pause: true
			});            
		},
    
		prepareTabs: function(i, slide) {
			return $rotation.tabs.eq(i);
		},

		activateTab: function(currentSlide, nextSlide) {
			var activeTab = $('a[href="#' + nextSlide.id + '"]', $rotation.context);
			if(activeTab.length) {
				$rotation.tabs.removeClass('on');
				activeTab.parent().addClass('on');
			}            
		}            
	};

	$(function() {
		$('body').addClass('js');
		$rotation.init();
	});  



	
});


