// 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/
	*/
	
	if ($(".menu_store ul").exists()) {
		$('.menu_store ul').addClass('sf-menu');
		$('.menu_store ul').css('display','block');
	}
	
	jQuery(function(){
		jQuery('.menu_store ul').superfish();
	});
	
	/*
		COLLECTION GALLERY
		Used in collections/index.tpl and collections/view.tpl 
	*/
	
	if ($("#collection ul").exists()) {
		$('#collection ul').jqGalScroll({height:455, width:920, ease:'easeInOutCubic', speed:0, perPage: 10});
	}
	
	/*
		DESIGNER GALLERY
		Used in designer/index.tpl and designer/view.tpl 
	*/
	
	if ($("#designer ul").exists()) {
		$('#designer ul').jqGalScroll({height:455, width:920, ease:'easeInOutCubic', speed:0, perPage: 10});
	}
	
	/*
		GALLERY PAGINATION
		Used in collections/index.tpl, collections/view.tpl, designer/index.tpl and designer/view.tpl 
	*/
	
	if ($("#galleryNav").exists()) {
		$('#galleryNav').easySlider({controlsBefore: '', controlsAfter: '', nextId: 'colNext', prevId: 'colPrev'});
	}
	
	/* 
		PAGINATION 
		Used in store/catalogue.tpl, store/category.tpl and press/index.tp
	*/
	
	if ($("#thumbView").exists()) {
		$("#thumbView").easySlider();
	}
	
	/*
		FANCY BOX
		Used in press/view.tpl and store/view.tpl
	*/
	
	if ($("a#single_image").exists()) {
		$("a#single_image").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': true });
	}
	
	if ($("a.fancybox_item").exists()) {
		$("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 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');
}
