// Check to see if the function Exists
jQuery.fn.exists = function(){
	return jQuery(this).length > 0;
}

$(document).ready(function(){
	
	/* 
		GALLERY
		Used in collections/index.tpl and collections/view.tpl 
	*/
	
	if ($("#gallery_thumbs").exists()) {
		$('.navigation').css('display', 'none');
		$('.content').css('display', 'block');
	
		// Initialize Advanced Galleriffic Gallery
		var gallery = $('#gallery_thumbs').galleriffic({
			delay:                     2500,
			numThumbs:                 10,
			preloadAhead:              10,
			enableTopPager:            true,
			enableBottomPager:         true,
			maxPagesToShow:            7,
			imageContainerSel:         '#slideshow',
			controlsContainerSel:      '#controls',
			captionContainerSel:       '',
			loadingContainerSel:       '#loading',
			renderSSControls:          false,
			renderNavControls:         true,
			playLinkText:              'play',
			pauseLinkText:             'pause',
			nextPageLinkText:          'Next',
			prevPageLinkText:          'Prev',
			enableHistory:             false,
			enableKeyboardNavigation:  true,
			autoStart:                 false,
			syncTransitions:           true,
			defaultTransitionDuration: 900,
			onPageTransitionOut:       function(callback) {
				this.fadeTo('fast', 0.0, callback);
			},
			onPageTransitionIn:        function() {
				this.fadeTo('fast', 1.0);
			}
		});
	}

	/* 
		PAGINATION 
		Used in store/catalogue.tpl, store/category.tpl and press/index.tp
	*/
	
		$("#thumbView").easySlider();

	
	/*
		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 });
	}

});

$(function(){
	/* 
		SUPERSIZE BACKGROUND
		Allow the background to be stretch along with the browser size
		and resize the image to fix the browser resolution.
	*/
	
	$.fn.supersized.options = {  
		startwidth: 1800,  
		startheight: 1150,
		vertical_center: 1,
		slideshow: 0,
		navigation: 0,
		transition: 0, //0-None, 1-Fade, 2-slide top, 3-slide right, 4-slide bottom, 5-slide left
		pause_hover: 0,
		slide_counter: 0,
		slide_captions: 0,
		slide_interval: 0  
	};
	
	$('#supersize').supersized(); 
	
});

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
	});
	set_first();
}


function set_first() {
	$('#alt_img_1').addClass('first');	
}


function ucc_submit() {
	if ($('#uccTo').val() != '') {
		$('#ucc_form').submit();
	}
}


function ucc_toggle() {
	$('#uccTo').val('');
	$('#uccToDiv').toggle('fast');
}
