$(document).ready(function(){


//
$(function($) {
$("div#information-required-mycw-orders img").fadeIn(5000); //Set opacity of main image
});

// HORIZONTAL SCROLLING TICKER
$("ul#ticker").liScroll();

// VERTICAL SCROLLING TESTIMONIALS
$('#testimonial-ticker').vTicker({ 
    speed: 800,
    pause: 4000,
    animation: 'fade',
    mousePause: false,
    showItems: 4
});
$('#testimonial-ticker ul li:odd').addClass("odd");
$('#testimonial-ticker ul li:even').addClass("even");

// ACCORDION
$("div#accordion").accordion();
$("div#accordion-span-four").accordion(
	{
 fillSpace: true
	}
);
$("div#accordion-span-five").accordion();
$("div#accordion-vintage-companies").accordion(
	{
	autoheight:false
	}
);

// TABBED CONTENT
$("div.tab-content").hide(); // Hide all tab content
$("ul.tabs li:first").addClass("active").show(); // Activate first tab
$("div.tab-content:first").show(); // Show first tab content
$("ul.tabs li").click(function() {
$("ul.tabs li").removeClass("active"); // Remove any "active" class
$(this).addClass("active"); // Add "active" class to selected tab
$("div.tab-content").hide(); // Hide all tab content
var activeTab = $(this).find("a").attr("href"); // Find the href attribute value to identify the active tab + content
$(activeTab).show(); // Show the active tab content
return false;
});

// SHARE THIS PAGE
$("div#share-this-page").bookmark({
	sites: ['facebook', 'twitter', 'delicious', 'digg', 'stumbleupon']
});

// WINDOW SLIDER
var sliderOptions = {
    easing: "easeInOutExpo",             // Anything other than "linear" or "swing" requires the easing plugin
    autoPlay: true,                      // This turns off the entire FUNCTIONALY, not just if it starts running or not.
    delay: 6000,                         // How long between slide transitions in AutoPlay mode
    startStopped: false,                 // If autoPlay is on, this can force it to start stopped
    animationTime: 2500,                 // How long the slide transition takes
    hashTags:false,                      // Should links change the hashtag in the URL?
    buildNavigation: true,              // If true, builds and list of anchor links to link to each slide
    pauseOnHover: false,                 // If true, and autoPlay is enabled, the show will pause on hover
    startText: "Go",
    stopText: "Stop"
};

$("div#window-slider-packages, div#window-slider-460px, div#window-slider-780px, div#window-slider-cms, div#thumbnail-slider, div#window-slider-cms-feature")
	.windowSlider(sliderOptions);

// 	LATEST NEWS TICKER
if($("ul#latest-news-ticker").length > 0)
{
	$("ul#latest-news-ticker").rss({
		feeds			: ['http://feeds.reuters.com/reuters/smallBusinessNews'],
		sortOrder		: 'desc',
		entriesPerFeed	: 5,
		dateFormat		: 'd/m/Y H:i',
		mode			: 'withPreviews',
		effect			: 'fade',
		effectCount		: 2
	});
}

// Set initial values
$("div#portfolio-image img").animate({ opacity: 1 }, 1 ); //Set opacity of main image
$("div#portfolio-thumbs div.th").animate({ opacity: 0.40 }, 1 ); //Set opacity of thumbnail images
$("div#portfolio-title").show(); //Show title
//$("div#portfolio-link").show(); //Show link
$("li#first-slide div.th:first").addClass('active').animate({ opacity:1}, 1,function(){ // Find the info from the first thumb and insert in main image
//Set Variables
var imgAlt = $(this).find('img').attr("alt"); //Get alt tag of image
var imgURL = $(this).find('a').attr("href"); //Get main image URL
var imgTitle = $(this).find('div.portfolio-title-block').html(); //Get HTML of title
var imgDesc = $(this).find('div.portfolio-link-block').html(); //Get HTML of link block
var imgDescHeight = $("div#link").find('div.portfolio-link-block').height();// Calculate height of block		
// Animate the main image		
$("div#portfolio-image img").animate({ opacity: 0 }, 250 , function() {
$("div#portfolio-image img").attr({ src: imgURL , alt: imgAlt}).animate({ opacity: 1 }, 250 );
});
// Animate the title
$("div#portfolio-title div.portfolio-title-block").animate({}, 1 , function() {
$("div#portfolio-title div.portfolio-title-block").html(imgTitle).animate({}, 1);
});
// Animate the link
$("div#portfolio-link div.portfolio-link-block").animate({}, 1 ,function() {
$("div#portfolio-link div.portfolio-link-block").html(imgDesc).animate({}, 1);
});
// Thumbnail hover events
$("div#portfolio-thumbs div.th").mouseover(function(){ // On hover
if ($(this).is(".active")) {  // If it's active, then...
return false; // Don't animate
} else {
$(this).animate({ opacity: 1}, 200); // Animate to 100% opacity
}
});
$("div#portfolio-thumbs div.th").mouseout(function(){ // Remove hover
if ($(this).is(".active")) {  //If it's active, then...
return false; // Don't animate
} else {
$(this).animate({ opacity: 0.40 }, 200); // Animate to 40% opacity
}
});
// Thumbnail Click events
$("div#portfolio-thumbs div.th").click(function(){ 
//Set Variables
var imgAlt = $(this).find('img').attr("alt"); //Get alt tag of image
var imgURL = $(this).find('a').attr("href"); //Get main image URL
var imgTitle = $(this).find('div.portfolio-title-block').html(); //Get HTML of title
var imgDesc = $(this).find('div.portfolio-link-block').html(); //Get HTML of link block
var imgDescHeight = $("div#link").find('div.portfolio-link-block').height();// Calculate height of block		
if ($(this).is(".active")) {  //If it's already active, then...
return false; // Don't click through
} else {
// Animate the main image		
$("div#portfolio-image img").animate({ opacity: 0 }, 250 , function() {
$("div#portfolio-image img").attr({ src: imgURL , alt: imgAlt}).animate({ opacity: 1 }, 250 );
});
// Animate the title
$("div#portfolio-title div.portfolio-title-block").animate({}, 1 , function() {
$("div#portfolio-title div.portfolio-title-block").html(imgTitle).animate({}, 1);
});
// Animate the link
$("div#link div.portfolio-link-block").animate({}, 1 ,function() {
$("div#link div.portfolio-link-block").html(imgDesc).animate({}, 1);
});
}
// Animate the thumbnails
$("div#portfolio-thumbs div.th").removeClass('active').animate({ opacity: 0.4}, 1); // Remove class of 'active' from active li
$(this).addClass('active').animate({ opacity:1 }, 1);  //add class of 'active' on clicked li only
return false;
});	
});

// Search text onclick
var searchSelected = false;
$('#page-header-search-input input').focus(function()
{
	if(this.value == 'Enter Keyword(s)')
	{
		this.value='';
	}
	else if(!searchSelected)
	{
		this.select();
		searchSelected = true;
	}
});

$('#page-header-search-input input').blur(function()
{
	if(this.value == '')
	{
		this.value = 'Enter Keyword(s)';
	}
	searchSelected = false;
});

// Company Name Search (if present on page)
if( $("#company-name-search-button input").length > 0 )
{
	var companyNameSearchSelected = false;
	$("#company-name-search-input input").click(function()
	{
		if(!companyNameSearchSelected)
		{
			this.select();
			companyNameSearchSelected = true;
		}
	});
	$("#company-name-search-input input").blur(function()
	{
		companyNameSearchSelected = false;
	});
	
	$("#company-name-search-button input").colorbox(
	{
		width		:	"844px",
		height		:	"520px",
		href		:	'/company-name-search/searching',
		iframe		:	true
	});
}



// Site map
$(".sitemap .expand").click(function()
{
	$(this).toggleClass('expanded');
	$(this).parent().find('ul:first').toggle(500, 'easeInOutExpo');
});

// Login page
$email = $('#login #email_address');
$password = $('#login #password');

if($email.length > 0 && !$email.val())
{
	$email[0].select();
}

if($password.length > 0 && $email.length > 0 && $email.val())
{
	$password[0].select();
}


// Pages inside iframes - add url parameters to links
if(location.pathname.indexOf('/iframe/true') > -1)
{
	$('a').each(function()
	{
		if(this.href.indexOf('/iframe/true') == -1)
		{
			strings = this.href.split('#');
			this.href = strings[0] + '/iframe/true';
			if(strings[1] !== undefined)
			{
				this.href += '#' + strings[1];
			}
		}
	});
}

// CMS Expanding boxes
$('.expanding-box-more').click(function(){
	$(this).text($(this).text() == 'Hide' ? 'More' : 'Hide');
	$(this).toggleClass('expanded');
	$(this).parent().find('.expanding-box-hidden-content').slideToggle();
});

});


