﻿/* Site-wide code */
/* ! Don't forget to use jQuery() not $() as Kentico uses non-conflict mode. */

// On page load...
jQuery(document).ready(function () {

	/* . Content sliders */

	// news page slider
	if (jQuery('#slider ul li').length > 1) {
		// only start if more than one item
		jQuery("#slider").easySlider({
			auto: true,
			continuous: true,
			pause: 5000,
			speed: 2000
		});
	}
	else if (jQuery('#slider ul li').length == 1) {
		// only 1 image, don't initialise slider
	}
	else if (jQuery('#slider ul li').length < 1) {
		// no images, hide slider
		jQuery("#slider").hide();
	}

	// The slider on the news page has stopped working - because the HTML has changed in the query transformation
	// news page slider (again)
	if (jQuery('#slider3 img').length > 1) {
		// only start if more than one item
		jQuery("#slider3").nivoSlider({
			effect: 'fade',
			animSpeed: 500,
			pauseTime: 5000,
			manualAdvance: false,
			pauseOnHover: false
		});
	}
	else if (jQuery('#slider3 img').length == 1) {
		// only 1 image, don't initialise slider
	}
	else if (jQuery('#slider3 img').length < 1) {
		// no images, hide slider
		jQuery("#slider3").hide();
	}

	// Where is this used?
	jQuery('#s1').cycle({
		fx: 'fade',
		speed: 500,
		slideshowSpeed: 3000
	});

	// Where is this used?
	jQuery('#slider1').nivoSlider({
		effect: 'fade',
		animSpeed: 500,
		pauseTime: 3000,
		pauseOnHover: false
	});

	// Where is this used?
	try 
	{
		jQuery('#slider2').nivoSlider({
			effect: 'fade',
			animSpeed: 500,
			pauseTime: 3000,
			manualAdvance: true,
			pauseOnHover: false
		});
	}
	catch (oh) 
	{
	}
	// 



	/* . Overlays */

	//Examples of how to assign the ColorBox event to elements
	jQuery("a[rel='example1']").colorbox();
	jQuery("a[rel='example2']").colorbox({ transition: "fade" });
	jQuery("a[rel='example3']").colorbox({ transition: "none", width: "75%", height: "75%" });
	jQuery("a[rel='example4']").colorbox({ slideshow: true });
	jQuery(".example5").colorbox();
	jQuery(".example6").colorbox({ iframe: true, innerWidth: 425, innerHeight: 344 });
	jQuery(".example7").colorbox({ width: "400px", innnerWidth: "400px", height: "535px", inline: true, href: "#inline_example2" });
	jQuery(".register").colorbox({ width: "400px", innnerWidth: "400px", height: "535px", inline: true, href: "#inline_example1" });

	// Oliver Price on 24/08/2011: Added the following four items to allow display of different forms on the MyCar.aspx page.
	jQuery(".editCurrentCar").colorbox({ width: "400px", innnerWidth: "400px", height: "535px", inline: true, href: "#divEditCurrentCar" });
	jQuery(".archiveCurrentCar").colorbox({ width: "400px", innnerWidth: "400px", height: "535px", inline: true, href: "#divArchiveCurrentCar" });
	jQuery(".addCurrentCar").colorbox({ width: "400px", innnerWidth: "400px", height: "535px", inline: true, href: "#divAddCurrentCar" });
	//jQuery(".editSecondaryCar").colorbox({ width: "400px", innnerWidth: "400px", height: "535px", inline: true, href: "#divEditSecondaryCar" });
	jQuery(".editCurrentCarReminders").colorbox({ width: "400px", innnerWidth: "400px", height: "535px", inline: true, href: "#divEditCurrentCarReminders" });
	jQuery(".editSecondaryCarReminders").colorbox({ width: "400px", innnerWidth: "400px", height: "535px", inline: true, href: "#divEditSecondaryCarReminders" });

	jQuery("button.find-another-dealer").colorbox({ width: "400px", innnerWidth: "400px", height: "250px", inline: true, href: "#inline_dealers_change" });
	jQuery("#colorbox").appendTo('form');
	// To manually open an overlay, call overlay(overlayidentifier, overlaywidth, overlayheight);
	// E.g., overlay(".zoneBottom", 400, 200);


	/* . Tipsy tooltips */

	// Enable tooltips
	jQuery('#example-1').tipsy({ gravity: 's', fade: true });
	jQuery('.example-2').tipsy({ gravity: 's', fade: true });


	/* . Events */
	// Open external links in a new window
	jQuery("a[rel=external]").click(function () {
		window.open(this.href);
		return false;
	});
});



// Custom functions

// Open an overlay
function overlay(overlayidentifier, overlaywidth, overlayheight) {
    jQuery.colorbox({ width: overlaywidth + "px", innnerWidth: overlaywidth + "px", height: overlayheight + "px", inline: true, href: overlayidentifier });
}

// function for the "Own An Alfa" checkbox
function toggleOwnAlfa(checkbox) 
{
	if (checkbox.checked)
	{
		jQuery('#ownanalfahiddenform').show();
		jQuery('#tdcarmodeltextbox').hide();
		jQuery('#tdcarmodeldropdown').show();
		jQuery('#tdoptinmagazine').show();
		jQuery('#tdoptinmagazinelbl').show();
		jQuery('#tdoptinsms').show();
		jQuery('#tdoptinsmslbl').show();
		jQuery('#tdoptinphone').show();
		jQuery('#tdoptinphonelbl').show();
		jQuery('#tdcarmaketextbox input:text').attr('disabled', true);
		jQuery('#tdcarmaketextbox input:text').val('Alfa Romeo');
	}
	else
	{
		jQuery('#ownanalfahiddenform').hide();
		jQuery('#tdcarmodeltextbox').show();
		jQuery('#tdcarmodeldropdown').hide();
		jQuery('#tdoptinmagazine').hide();
		jQuery('#tdoptinmagazinelbl').hide();
		jQuery('#tdoptinsms').hide();
		jQuery('#tdoptinsmslbl').hide();
		jQuery('#tdoptinphone').hide();
		jQuery('#tdoptinphonelbl').hide();
		jQuery('#tdcarmaketextbox input:text').attr('disabled', false);
		jQuery('#tdcarmaketextbox input:text').val('');
	}
}

