/*

	AustralianTies.com.au
	© Coded by ctrlog.com
	Last Update on 06/10/2010

*/

// Global functions

// Show welcome images
var image_count = 1;

function switch_welcome_image() {

	var image_url = '/static/images/welcome/';

	if(image_count == 1){
		welcome_image = image_url + '1.jpg';
	} else if(image_count == 2){
		welcome_image = image_url + '2.jpg';
	} else if(image_count == 3){
		welcome_image = image_url + '3.jpg';
	} else if(image_count == 4){
		welcome_image = image_url + '4.jpg';
	} else if(image_count == 5){
		welcome_image = image_url + '5.jpg';
	} else if(image_count == 6){
		welcome_image = image_url + '6.jpg';
	} else if(image_count == 7){
		welcome_image = image_url + '7.jpg';
	} else if(image_count == 8){
		welcome_image = image_url + '8.jpg';
	} else if(image_count == 9){
		welcome_image = image_url + '9.jpg';
		image_count = 0;
	}
	
	$('.welcome-image img').hide();
	$('.welcome-image img').attr('src', welcome_image);
	$('.welcome-image img').load(function(){
		 $('.welcome-image img').fadeIn(1000, function(){ $('.welcome-image').css('backgroundImage','url(' + welcome_image +')'); });
	});
	
	if(image_count < 5 || image_count == 9){
		$('.welcome-image a').attr('href', '/ties');
	} else {
		$('.welcome-image a').attr('href', '/cufflinks');
	}
	
	image_count = image_count + 1;
	
	window.setTimeout('switch_welcome_image();', 6000);
	
}

// Initialize on page load
$(document).ready(function(){

	switch_welcome_image()

	// Highlight borders on input focus
	$('.text').focus(function () {
		$(this).css({ borderColor: '#e8cb06' });
	});
	
	// Restore borders on input blur
	$('.text').blur(function () {
		$(this).css({ borderColor: '#cccccc' });
	});

	// Toggle portfolio images	
	$('.portfolio .thumb-navigation a').click(function(){
		image = $(this).attr('href');
		name = $(this).find('img').attr('alt');
		$('.portfolio .thumb-navigation a').removeClass('active');
		$(this).addClass('active');
		$(this).parent().parent().parent().parent().find('.image-box .description h3').html(name);
		$(this).parent().parent().parent().parent().find('.image-box img#loading').show();
		$(this).parent().parent().parent().parent().find('.image-box img#full-image').hide();
		$(this).parent().parent().parent().parent().find('.image-box img#full-image').attr('src', image);
		$(this).parent().parent().parent().parent().find('.image-box img#full-image').load(function(){
			$(this).parent().parent().parent().parent().find('.image-box img#loading').hide();
			$(this).parent().parent().parent().parent().find('.image-box img#full-image').fadeIn('slow', function(){ $(this).parent().parent().parent().parent().find('.image-box').css('backgroundImage','url(' + image +')'); });
		});
		return false;
	});
	
	// Tab navigation
	$('.design .navigation a').click(function(){
		var box = $(this).attr('href');
		$('.design .navigation a').removeClass('active');
		$(this).addClass('active');
		$('.design .image-box').hide();
		$(box).show();
		return false;
	});
	
	// Popup Box
	$('a#popup-box-trigger').click(function(){
		var popupbox = $(this).attr('href');
		$(popupbox).fadeIn(200);
		return false;
	});
	
	$('.popup-box .content .image-box a.close').click(function(){
		$(this).parent().parent().parent().parent().fadeOut(200);
		return false;
	});
	
	// Popup Box
	$('.step-element').hover(function(){
		$(this).find('.product-step-box').fadeIn(200);
	}, function(){
		$(this).find('.product-step-box').fadeOut(200);
	});
	
	// About us tooltips
	$('.about-us .why-us ul li a').hover(function(){
		$(this).parent().find('.icon-box').animate({ opacity: 'show', marginTop: '190px' }, 200);
	}, function(){
		$(this).parent().find('.icon-box').animate({ opacity: 'hide', marginTop: '240px' }, 200);
	});
	
});
