/**
 * @author kiril
 * 
 * File configuration for all jScript components
 */

currentCount = 1;
function countIt(curCount) {
	currentCount = parseInt(curCount);
	if (currentCount < 1) {
		currentCount = 1;
	}
};

function nextImg() {
	currentCount = parseInt(currentCount, 10);
	var nextImage = currentCount + 1;
	$("#gallery-thumbs .items").find('img[alt=' + nextImage + ']').click();
};
function previousImg() {
	currentCount = parseInt(currentCount, 10);
	var previousImage = currentCount - 1;
	if (previousImage < 1) {
		previousImage = 1;
	}
	$("#gallery-thumbs .items").find('img[alt=' + previousImage + ']').click();
};

$(document).ready(function() {
	// ******** initialize superfish menu **********
		if ($('ul.sf-menu').length > 0) {
			$('ul.sf-menu').supersubs( {
				minWidth : 12, // minimum width of sub-menus in em units
				maxWidth : 25, // maximum width of sub-menus in em units
				extraWidth : 1
			// extra width can ensure lines don't sometimes turn over
					// due to slight rounding differences and font-family
					}).superfish( {
				autoArrows : false
			}); // call supersubs first, then superfish, so that subs are
			// not display:none when measuring. Call before initialising
			// containing tabs for same reason.
		}


		// ********** initialize installations showcase scrollable *************
		if ($("#featured-installations").length > 0) {
			$("#featured-installations").scrollable( {
				size : 1,
				easing : "swing",
				loop : false,
				speed : 800
			});
		}

		// ********** initialize page slideshows *************
		$(".slideimages").tabs(".slides > div", {
			// enable "cross-fading" effect
			effect : 'fade',
			fadeInSpeed : 1000,
			fadeOutSpeed : 1000,
			// start from the beginning after the last tab
			rotate : true
		// use the slideshow plugin. It accepts its own configuration
				}).slideshow( {
			autoplay : true,
			interval : 5000
		});


	// ********** initialize thumb gallery ******
	if ($('div.scrollable.thumbs').length > 0) {
		
		$('div.scrollable.thumbs').scrollable( {
			size : 5,
			easing : "swing",
			loop : false,
			speed : 800, 
			clickable: false
		});
	}

	// ********** initialize Pretty Photo lightbox ******
	if ($("a[rel^='prettyPhoto']").length > 0) {

			$("a[rel^='prettyPhoto']").prettyPhoto({
				overlay_gallery: false	
			});
		
		}
	
	
	
	// ********** Initialize GA cookies interface ******		
	var gac = new gaCookies();
	var cRefer = "Domain: " + referringDomain + " | GA Id: " + gac.getUniqueId() + " | Source: " + gac.getCampaignSource() + " | Medium: " + gac.getCampaignMedium() + " | Content: " + gac.getCampaignContent();
	
	var initialVisitTime = new Date(gac.getInitialVisitTime() * 1000);
	var currentVisitTime = new Date(gac.getCurrentVisitTime() * 1000);
	var cDateRef = "Initial Visit: " + initialVisitTime.toDateString() + " - " + initialVisitTime.toTimeString();
    cDateRef += "Current Visit: " + currentVisitTime.toDateString() + " - " + currentVisitTime.toTimeString();
	
	
		
	// ************ Set hidden form fields for referrer value and date for tracking ******************	
    
    if ($("#refer").length > 0) {
        $("#refer").val(cRefer);
    }
    if ($("#refer_date").length > 0) {
        $("#refer_date").val(cDateRef);
    }

	});

