// Check to see if the function Exists
jQuery.fn.exists = function(){
	return jQuery(this).length > 0;
}
	
$(document).ready(function(){
						   
	/*
		MENU
		User superfish to create the drop down menues in menu.tpl 
		Superfish - v 1.4.8 http://users.tpg.com.au/j_birch/plugins/superfish/
	*/
	
	jQuery(function(){
		jQuery('ul.sf-menu').superfish();
	});

	/* 
		PAGINATION 
		Used in store/catalogue.tpl, store/category.tpl and press/index.tpl
	*/
	
	if ($("#thumbView").exists()) {
		$("#thumbView").easySlider();
	}
	
	/*
		COLLECTION GALLERY
		Used in collections/index.tpl and collections/view.tpl 
	*/
	if ($("#gallery_thumbs").exists()) {
		$('#gallery_content').css('display', 'block');
	
		// Initially set opacity on thumbs and add
		// additional styling for hover effect on thumbs
		var onMouseOutOpacity = 0.67;
		$('#gallery_thumbs ul.thumbs li').opacityrollover({
			mouseOutOpacity:   onMouseOutOpacity,
			mouseOverOpacity:  1.0,
			fadeSpeed:         'fast',
			exemptionSelector: '.selected'
		});
		
		// Initialize Advanced Galleriffic Gallery
		var gallery = $('#gallery_thumbs').galleriffic({
			delay:                     2500,
			numThumbs:                 9,
			preloadAhead:              9,
			enableTopPager:            false,
			enableBottomPager:         true,
			maxPagesToShow:            7,
			imageContainerSel:         '#slideshow',
			controlsContainerSel:      '#controls',
			captionContainerSel:       '#caption',
			loadingContainerSel:       '#loading',
			renderSSControls:          true,
			renderNavControls:         false,
			playLinkText:              'play',
			pauseLinkText:             'pause',
			nextPageLinkText:          'Next',
			prevPageLinkText:          'Prev',
			enableHistory:             false,
			autoStart:                 false,
			syncTransitions:           true,
			defaultTransitionDuration: 900,
			onSlideChange:             function(prevIndex, nextIndex) {
				// 'this' refers to the gallery, which is an extension of $('#thumbs')
				this.find('ul.thumbs').children()
					.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
					.eq(nextIndex).fadeTo('fast', 1.0);
			},
			onPageTransitionOut:       function(callback) {
				this.fadeTo('fast', 0.0, callback);
			},
			onPageTransitionIn:        function() {
				this.fadeTo('fast', 1.0);
			}
		});
	}
	
	/*
		FANCY BOX
		Used in press/view.tpl and store/view.tpl
	*/
		$("a#single_image").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': true });
		$("a.fancybox_item").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': true });
		
	/*
		FANCY BOX - iFrame
		Used to display the contact form in a iFrame
	*/
	if ($("a.iframe").exists()) {
		$("a.iframe").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'frameWidth': 550, 'frameHeight': 270, 'overlayShow': true });
	}

	/*
		CART
		Fade the Flash Message In / Out 
	*/
	if ($("div.flash_message").exists()) {
		if($.trim($("div.flash_message").text()) == "") {
			$(".flash_message").remove();
		} else {
			$('div.flash_message').hide().fadeIn("slow");
			//$('div.flash_message').animate({opacity: 1.0}, 5000).fadeOut("slow");
		}
	}

});

function display_img(thumb_src, full_src, target, index) {
	$('.altimg').attr({
		"class" : "altimg"
	});
	$('#alt_img_' + index).attr({
		"class" : "altimg active"
	});
	$('#' + target + ' > a').attr({
		"href" : full_src
	});
	$('#' + target + ' > a > img').attr({
		"src" : thumb_src
	});
}


function ucc_submit() {
	if ($('#uccTo').val() != '') {
		$('#ucc_form').submit();
	}
}


function ucc_toggle() {
	$('#uccTo').val('');
	$('#uccToDiv').toggle('fast');
}

