/**
 * Main js file.
 * @author Mickael Jeanroy.
 */

//----- BLOCK UI CONFIGURATION

//----- HIGHSLIDE CONFIGURATION
hs.graphicsDir = '/libs/highslide/highslide/graphics/';
hs.align = 'center';
hs.transitions = ['expand', 'crossfade'];
hs.fadeInOut = true;
hs.dimmingOpacity = 0.50;
hs.wrapperClassName = 'borderless floating-caption';
hs.captionEval = 'this.thumb.alt';
hs.numberPosition = 'caption';
hs.lang.number = '';
hs.showCredits = false;
hs.showPrevious = true;
hs.showNext = true;
hs.showFullExpand = false;
hs.showClose = true;
hs.showMusic = true;
hs.showPlay = false;
hs.musicAutoplay = true;

// Add the slideshow providing the controlbar and the thumbstrip
hs.addSlideshow({
	slideshowGroup: 'group1',
	interval: 5000,
	repeat: false,
	useControls: false,
	overlayOptions: {
		className: 'text-controls',
		position: 'top center',
		relativeTo: 'viewport'
	},
	thumbstrip: {
		position: 'bottom center',
		mode: 'horizontal',
		relativeTo: 'viewport'
	}
});
hs.addSlideshow({
	slideshowGroup: 'group2',
	interval: 5000,
	repeat: false,
	useControls: false,
	overlayOptions: {
		className: 'text-controls',
		position: 'top center',
		relativeTo: 'viewport'
	},
	thumbstrip: {
		position: 'bottom center',
		mode: 'horizontal',
		relativeTo: 'viewport'
	}
});

//Add the simple close button
hs.registerOverlay({
	html: '<div class="closebutton" onclick="return hs.close(this)" title="Close"></div>',
	position: 'top right',
	fade: 2, // fading the semi-transparent overlay looks bad in IE
	useOnHtml: true
});

$.blockUI.defaults = { 
    // message displayed when blocking (use null for no message) 
    message:  '<img src="/images/loader.gif" />', 
 
    // styles for the message when blocking; if you wish to disable 
    // these and use an external stylesheet then do this in your code: 
    // $.blockUI.defaults.css = {}; 
    css: {
    	 padding:        '10px', 
         margin:         '10px', 
         width:          '30%', 
         top:            '40%', 
         left:           '35%', 
         textAlign:      'center'
    }, 
 
    // styles for the overlay 
    overlayCSS:  { 
        backgroundColor: '#000', 
        opacity:         0.6 
    }, 
 
    // styles applied when using $.growlUI 
    growlCSS: { 
        width:    '350px', 
        top:      '10px', 
        left:     '', 
        right:    '10px', 
        border:   'none', 
        padding:  '5px', 
        opacity:   0.6, 
        cursor:    null, 
        color:    '#fff', 
        '-webkit-border-radius': '10px', 
        '-moz-border-radius':    '10px' 
    }, 
     
    // IE issues: 'about:blank' fails on HTTPS and javascript:false is s-l-o-w 
    // (hat tip to Jorge H. N. de Vasconcelos) 
    iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank', 
 
    // force usage of iframe in non-IE browsers (handy for blocking applets) 
    forceIframe: false, 
 
    // z-index for the blocking overlay 
    baseZ: 1000, 
 
    // set these to true to have the message automatically centered 
    centerX: true, // <-- only effects element blocking (page block controlled via css above) 
    centerY: true, 
 
    // allow body element to be stetched in ie6; this makes blocking look better 
    // on "short" pages.  disable if you wish to prevent changes to the body height 
    allowBodyStretch: true, 
 
    // enable if you want key and mouse events to be disabled for content that is blocked 
    bindEvents: true, 
 
    // be default blockUI will supress tab navigation from leaving blocking content 
    // (if bindEvents is true) 
    constrainTabKey: true, 
 
    // fadeIn time in millis; set to 0 to disable fadeIn on block 
    fadeIn:  200, 
 
    // fadeOut time in millis; set to 0 to disable fadeOut on unblock 
    fadeOut:  400, 
 
    // time in millis to wait before auto-unblocking; set to 0 to disable auto-unblock 
    timeout: 0, 
 
    // disable if you don't want to show the overlay 
    showOverlay: true, 
 
    // if true, focus will be placed in the first available input field when 
    // page blocking 
    focusInput: true, 
 
    // suppresses the use of overlay styles on FF/Linux (due to performance issues with opacity) 
    applyPlatformOpacityRules: true, 
 
    // callback method invoked when unblocking has completed; the callback is 
    // passed the element that has been unblocked (which is the window object for page 
    // blocks) and the options that were passed to the unblock call: 
    //     onUnblock(element, options) 
    onUnblock: null, 
 
    // don't ask; if you really must know: http://groups.google.com/group/jquery-en/browse_thread/thread/36640a8730503595/2f6a79a77a78e493#2f6a79a77a78e493 
    quirksmodeOffsetHack: 4 
};
//----- BLOCK UI CONFIGURATION

$(document).ready(function() {
	initialize();
});

jQuery.extend(jQuery.browser,
		{SafariMobile : navigator.userAgent.toLowerCase().match(/iP(hone|ad)/i) }
);

var timerHome = null;

/**
 * Check if an email is valid.
 * 
 * @param {string} email
 *            Email to check.
 * @returns {boolean} True if email is valid, false otherwise.
 */
function checkEmail(email) {
	if ((email == null) || (email.length == 0)) {
		return false;
	}
	var regexEmail = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/;
	return regexEmail.test(email);
}

/**
 * Check if a phone number is valid.
 * 
 * @param {string} phoneNumber
 *            Phone number to check.
 * @returns {boolean} True if phone number is valid, false otherwise.
 */
function checkPhone(phoneNumber) {
	return true;
}

/**
 * Remove withespace in the begining and in the end of a string.
 * 
 * @param {string} myString
 *            String to trim.
 * @returns {string} String trimed.
 */
function trim (myString) {
	return myString.replace(/^\s+/g,'').replace(/\s+$/g,'') 
}

/**
 * Check if browser is IE6.
 * 
 * @returns {Boolean} True if browser is IE6, false otherwise.
 */
function isIE6() {
	return ($.browser.msie) && ($.browser.version=="6.0");
}

/**
 * Check if browser is IE7.
 * 
 * @returns {Boolean} True if browser is IE7, false otherwise.
 */
function isIE7() {
	return ($.browser.msie) && ($.browser.version=="7.0");
}

/**
 * Check if browser is IE8.
 * 
 * @returns {Boolean} True if browser is IE8, false otherwise.
 */
function isIE8() {
	return ($.browser.msie) && ($.browser.version=="8.0");
}

/**
 * Check if browser is Safari for IOs.
 * 
 * @returns {Boolean} True if browser is Safari for IOs, false otherwise.
 */
function isIOs() {
	return $.browser.SafariMobile;
}

/**
 * Compute window width.
 * 
 * @returns {float} Window with.
 */
function getWindowWidth() {
	if (typeof( window.innerWidth ) == 'number') {
		return window.innerWidth;
	} else if ((document.documentElement) && ((document.documentElement.clientWidth) || (document.documentElement.clientHeight))) {
		return document.documentElement.clientWidth;
	} else if ((document.body) && ((document.body.clientWidth) || (document.body.clientHeight))) {
		return document.body.clientWidth;
	}
	return 0;
}

/**
 * Compute window heighr.
 * 
 * @returns {float} Window height.
 */
function getWindowHeight() {
	if (typeof(window.innerWidth ) == 'number') {
		return window.innerHeight;
	} else if ((document.documentElement) && ((document.documentElement.clientWidth) || (document.documentElement.clientHeight))) {
		return document.documentElement.clientHeight;
	} else if ((document.body) && ((document.body.clientWidth) || (document.body.clientHeight))) {
		return document.body.clientHeight;
	}
	return 0;
}

/**
 * Initialize web app (links on nav bar, hisorization etc...).
 */
function initialize() {
	initializeHistoryPlugin();
	bindResize();
	initMenu();
	fixPlaceholder();
	setRolloverSocialButtons();
	onSubscribe();
}

/**
 * Bind resize window event with a customized function.
 */
function bindResize() {
	$(window).resize(function() {
		onWindowResize();
	});
}

/**
 * Call each time window is resized.
 */
function onWindowResize() {
}

/**
 * Close event. Called when min content changed.
 */
function close() {
	$(window).unbind("scroll");
	stopTimer();
}

/**
 * Fix placeholder parameter for old browser like sucking IE.
 */
function fixPlaceholder() {
	// do it only if placeholder attribute is not supported
	if (!Modernizr.input.placeholder) {
		$('[placeholder]').focus(function() {
			var input = $(this);
			if (input.val() == input.attr('placeholder')) {
				input.val('');
				input.removeClass('placeholder');
			}
		}).blur(function() {
			var input = $(this);
			if (input.val() == '' || input.val() == input.attr('placeholder')) {
				input.addClass('placeholder');
				input.val(input.attr('placeholder'));
			}
		}).blur();
	}
}

/**
 * Initialize rollover on social buttons displayed in footer.
 */
function setRolloverSocialButtons() {
	$('#footer img').hover(function() {
		var rollOn = $(this).attr('data-rollOn');
		$(this).attr('src', rollOn);
	}, function() {
		var rollOut = $(this).attr('data-rollOut');
		$(this).attr('src', rollOut);
	});
}

/**
 * Plugs "subscribe" buttons.
 * Check user inputs, display an error message if needed or call subscribe
 * function on backend.
 */
function onSubscribe() {
	$('#submit-email').click(function() {
		$('#form-subscribe').submit();
		return false;
	});

	$('#form-subscribe').submit(function() {
		var email = $('#subscribe-email').val();
		email = trim(email);
		if (!checkEmail(email)) {
			if ($.browser.SafariMobile) {
				// Use default alert system on iOS
				alert($("#errorEmail").html());
			} else {
				var $dialog = $("#errorEmail").dialog({
					autoOpen: false,
					modal: true,
					buttons: {
						Ok: function() {
							$(this).dialog("close");
						}
					}
				});
				$dialog.dialog('open');
			}
		} else {
			subscribe();
		}
		return false;
	});
}

/**
 * Send user inputs on subscription form, send it to backend and display result.
 */
function subscribe() {
	var subscriptionUrl = $('#form-subscribe').attr('action');
	var nameParamEmail = $('#subscribe-email').attr('name');
	var nameParamLanguage = $('#language-fr').attr('name');

	var email = $('#subscribe-email').val();
	email = trim(email);

	var language = $("input[@name=" + nameParamLanguage + "]:checked").val();

	$.ajax({
		type : "POST",
		url : subscriptionUrl,
		data : nameParamEmail + "=" + email + "&" + nameParamLanguage + "=" + language,
		success : function(msg) {
			clickOnSubscribe = false;
			$('#subscribe-email').val("");
			hideSubscribeForm();
			showToastInformation(msg);
		},
		error : function() {
			var $dialog = $("#errorEmailFailed").dialog({
				autoOpen: false,
				modal: true,
				buttons: {
					Ok: function() {
						$(this).dialog("close");
					}
				}
			});
			$dialog.dialog('open');
		}
	});
}

/**
 * Show information using toaster style.
 * @param {string} message Message to display.
 */
function showToastInformation(message) {
	$().toastmessage('showToast', {
		text : message,
		sticky : false,
		position : 'top-right',
		type : 'notice',
		stayTime: 3000,
		closeText: '',
		close : function () {}
	});
}

/** {boolean} Use to know has click to show subscription form. */
var clickOnSubscribe = false;

/** {boolean} Use to know if mouse is hover subscription form */
var hoverFormSubscribe = false;

/**
 * Initialize main navigation bar (main menu).
 */
function initMenu() {
	$("#menu a").click(function() {
		var item = $(this);
		if (!item.hasClass('no-manage')) {
			var link = item.attr("href");
			goTo(link);
			return false;
		}
	});

	$('#menu-subscribe').hover(function() {
		if (clickOnSubscribe) {
			showSubscribeForm();
		}
	}, function() {
		clickOnSubscribe = false;
		setTimeout('hideSubscribeForm()', 500);
	});

	$('#menu-subscribe a').click(function() {
		clickOnSubscribe = !clickOnSubscribe;
		if (clickOnSubscribe) {
			showSubscribeForm();
		} else {
			hideSubscribeForm();
		}
	});

	$('#form-subscribe').hover(function() {
		hoverFormSubscribe = true;
	}, function() {
		hoverFormSubscribe = false;
		setTimeout('hideSubscribeForm()', 500);
	});
}

/**
 * Setup subscription form to be shown under subscribe menu.
 */
function setupSubscribeForm() {
	var left = $('#menu-subscribe a').position().left;
	$('#form-subscribe').css('left', left + 'px');
}

/**
 * Setup subscription form and show it.
 */
function showSubscribeForm() {
	setupSubscribeForm();
	$('#form-subscribe').slideDown('slow');
}

/**
 * Hide subscription form.
 */
function hideSubscribeForm() {
	if ((!mouseIsHoverFormSubscribe()) && (!inputEmailHasFocus())) {
		$('#form-subscribe').slideUp('slow');
	}
}

/**
 * Check if mouse is hover subscription form.
 * 
 * @returns {boolean} True if mouse is hover subscription form, false otherwise.
 */
function mouseIsHoverFormSubscribe() {
	return $('#form-subscribe').is(':visible') && hoverFormSubscribe;
}

/**
 * Check if input to type email subscription has focus.
 * 
 * @returns {boolean} True if input to type email subscription has focus, false
 *          otherwise.
 */
function inputEmailHasFocus() {
	return $("#subscribe-email").is(":focus");
}

/**
 * Initialize history plugin.
 */
function initializeHistoryPlugin() {
	$.history.init(function(hash){
		if (hash == "") {
			changeContent("/index/home");
		} else {
			changeContent(hash);
		}
	},
	{ unescape: ",/" });
}

/**
 * Check if link is valid and change content / manage history if it his.
 * 
 * @param link
 *            {string} Link to get.
 */
function goTo(link) {
	if (link == '#') {
		return;
	}
	if ((link != '#') && (link.length > 1)) {
		var char = link.substring(0, 1);
		if (char == '#') {
			link = link.substring(1);
		}
	}
	if (link == "/") {
		link = "/index/home";
	}
	jQuery.history.load(link);
}

/**
 * Get content for a link and display it.
 * 
 * @param link
 *            {string} Link to get.
 */
function changeContent(link) {
	if (link == '#') {
		return;
	}

	$.blockUI();
	if (link == "/") {
		link = "/index/index";
	}
	close();
	$.ajax({
		type : "GET",
		url : link,
		data : "fromJs=true",
		success : function(msg) {
			$('#main-content').html(msg);
			bindResize();
			$('html, body').animate({ scrollTop: 0 }, 0);
			$.unblockUI();
		},
		error : function() {
			$.unblockUI();
		}
	});
}

function initLinksProjectPhotos() {
	$('#projects-photos a').click(function() {
		var item = $(this);
		var link = item.attr("href");
		if (link != "#") {
			goTo(link);
		}
		return false;
	});
	
	$('.bar2').mosaic({
		animation	:	'slide'
	});
}

/**
 * Use to initialize photo project view.
 */
function projectPhotos() {
	manageScrollPhotographies();
	manageClickPhotographies();
	manageInfosPhotographies();
	manageStockInquiry();
	manageBuyPrint();
}

function manageClickPhotographies() {
	$('#thumbnails a').click(function() {
		var img = $(this).attr('href');
		goToByScroll(img);
		$('#thumbnails a').each(function() {
			$(this).parent().parent().removeClass('thumbnail-active');
		});
		$(this).parent().parent().addClass('thumbnail-active');
		return false;
	});
}

function goToByScroll(id){
	var scrollPosition = $("#" + id).offset().top  - 120;
	$('html,body').animate({scrollTop: scrollPosition}, 'slow');
}

function manageInfosPhotographies() {
	$('.display-img-infos').click(function() {
		var imgInfo = $(this).prev().prev();
		var hideImgInfo = $(this).next();

		imgInfo.slideDown('slow');
		hideImgInfo.show();
		$(this).hide();
		return false;
	});

	$('.hide-img-infos').click(function() {
		var imgInfo = $(this).prev().prev().prev();
		var displayImgInfo = $(this).prev();

		imgInfo.slideUp('slow');
		displayImgInfo.show();
		$(this).hide();
		return false;
	});
}

function manageScrollPhotographies() {
	computeThumbnails();
	$(window).scroll(function() {
		if(($.browser.msie) && (($.browser.version=="6.0") || ($.browser.version=="7.0"))) {
			
		}
	});

	$(window).resize(function() {
		onWindowResize();
		computeThumbnails();
	});
}

function manageStockInquiry() {
	$('.btn-stock-inquiry').click(function() {
		var img = $(this).attr("data-img");
		$('#request-img').val(img);
		$('#modal-stock-inquiry').modal({
			  keyboard: true,
			  show: true,
			  backdrop: true
		});
	});
	$('#modal-stock-inquiry').bind('hidden', function() {
		resetSendRequestForm();
	});

	$('#request-submit').click(function() {
		checkFormRequest();
		return false;
	});
	fixPlaceholder();
}

function manageBuyPrint() {
	$('.btn-buy-print').click(function() {
		var img = $(this).attr("data-img-src");
		var width = $(this).attr("data-img-width");
		var height = $(this).attr("data-img-height");

		$('#buy-img').attr('src', img);
		$('#buy-img').attr('width', width);
		$('#buy-img').attr('height', height);

		var popupHeight = $('#modal-buy-print').outerHeight();
		var windowHeight = getWindowHeight();
		if (popupHeight >= windowHeight) {
			$('#modal-buy-print').css('bottom', '20px');
		} else {
			$('#modal-buy-print').css('bottom', 'auto');
		}
		$('#modal-buy-print').modal({
			  keyboard: true,
			  show: true,
			  backdrop: true
		});
	});
}

function hideSendRequestForm() {
	$('#modal-stock-inquiry').modal('hide');
	resetSendRequestForm();
}

function resetSendRequestForm() {
	$('#request-img').val('');
	$('#request-name').val('');
	$('#request-phone-number').val('');
	$('#request-email').val('');
}

function checkFormRequest() {
	$('#request-form').removeClass('input-error');

	var idProject = $('#request-idProject').val();
	var img = $('#request-img').val();
	var name = $('#request-name').val();
	var phoneNumber = $('#request-phone-number').val();
	var email = $('#request-email').val();

	email = trim(email);
	phoneNumber = trim(phoneNumber);
	name = trim(name);

	var validName = name != '';
	var validEmail = email != '' && checkEmail(email);
	var validPhone = checkPhone(phoneNumber);
	var valid = validName && validEmail && validPhone;
	if (!valid) {
		if (!validName) {
			$('#request-name').addClass('input-error');
		}
		if (!validPhone) {
			$('#request-phone-number').addClass('input-error');
		}
		if (!validEmail) {
			$('#request-email').addClass('input-error');
		}
		alert($("#errorSendRequest").html());
	} else {
		sendRequest();
	}
}

function sendRequest() {
	var sendRequestUrl = $('#request-form').attr('action');

	var nameParamIdProject = $('#request-idProject').attr('name');
	var nameParamImg = $('#request-img').attr('name');
	var nameParamName = $('#request-name').attr('name');
	var nameParamPhoneNumber = $('#request-phone-number').attr('name');
	var nameParamEmail = $('#request-email').attr('name');

	var idProject = $('#request-idProject').val();
	var img = $('#request-img').val();
	var name = $('#request-name').val();
	var phoneNumber = $('#request-phone-number').val();
	var email = $('#request-email').val();

	name = trim(name);
	phoneNumber = trim(phoneNumber);
	email = trim(email);

	var params = '';
	params += nameParamIdProject + '=' + idProject;
	params += '&';
	params += nameParamImg + '=' + img;
	params += '&';
	params += nameParamName + '=' + name;
	params += '&';
	params += nameParamPhoneNumber + '=' + phoneNumber;
	params += '&';
	params += nameParamEmail + '=' + email;

	$.ajax({
		type : "POST",
		url : sendRequestUrl,
		data : params,
		success : function(msg) {
			hideSendRequestForm();
			showToastInformation(msg);
		},
		error : function() {
			var $dialog = $("#sendRequestFailed").dialog({
				autoOpen: false,
				modal: true,
				buttons: {
					Ok: function() {
						$(this).dialog("close");
					}
				}
			});
			$dialog.dialog('open');
		}
	});
}

function computeThumbnails() {
	$("#thumbnails").jScrollPane();
	var left = $('#project').offset().left - 20;
	$("#thumbnails").css('left', left + 'px');
}

var leftCarousel = 0;
var freeSpace = 0;

function stopTimer() {
	if (timerHome != null) {
		clearInterval(timerHome);
		timerHome = null;
	}
}

function reinitTimer(fnNext, effectTimer) {
	stopTimer();
	timerHome = setInterval(fnNext, effectTimer);
}

function index() {
	$('#carousel_ul a').click(function() {
		var isNoLink = $(this).hasClass('nolink');
		var link = $(this).attr('href');
		if ((!isNoLink) && (link != '#')) {
			goTo(link);
		}
		return false;
	});
}

function initCarousel(imgWidth, imgHeight, effectDuration, effectTimer, marginLeft, marginRight) {
	// Add margin to image width
	var margin = marginLeft + marginRight;

	computeLeftCarousel(imgWidth, margin);
	setSizeOnCarousel(imgWidth, imgHeight, marginLeft, marginRight);

	$('#carousel_ul li:first').before($('#carousel_ul li:last'));  

	$('#prev').hover(function() {
		$('#left_scroll').fadeTo("fast", 0);
	}, function () {
		$('#left_scroll').fadeTo("fast", 0.7);
	});
	$('#next').hover(function() {
		$('#right_scroll').fadeTo("fast", 0);
	}, function () {
		$('#right_scroll').fadeTo("fast", 0.7);
	});

	var fnNext = function() {
		goToNext();
	};

	var fnPrev = function() {
		goToPrev();
	};

	reinitTimer(fnNext, effectTimer);

	$('#next').click(function(){
		stopTimer();
		goToNext();
		return false;
	});  

	$('#prev').click(function(){  
		stopTimer();
		goToPrev();
		return false;
	});

	function goToNext() {
		var moveTo = -leftCarousel - imgWidth;  
		$('#carousel_ul').animate({'left' : moveTo}, effectDuration, function(){  
			$('#carousel_ul li:last').after($('#carousel_ul li:first'));  
			$('#carousel_ul').css({'left' : '-' + leftCarousel + 'px'});  
		});
	}

	function goToPrev() {
		var moveTo = -leftCarousel + imgWidth;  
		$('#carousel_ul').animate({'left' : moveTo}, effectDuration, function(){
			$('#carousel_ul li:first').before($('#carousel_ul li:last'));
			$('#carousel_ul').css({'left' : '-' + leftCarousel + 'px'});
		});
	}

	$(window).resize(function() {
		onWindowResize();
		computeLeftCarousel(imgWidth, margin);
		setSizeOnCarousel(imgWidth, imgHeight, marginLeft, marginRight);
		getZoom();
	});
}

function computeLeftCarousel(imgWidth, margin) {
	var imgOuterWidth = imgWidth + margin;
	var windowWidth = getWindowWidth();

	leftCarousel = imgOuterWidth;
	freeSpace = windowWidth - imgOuterWidth;

	if (freeSpace > 0) {
		var nbImgOnLeft = 2;
		freeSpace = freeSpace / 2;
		leftCarousel = imgOuterWidth * nbImgOnLeft - freeSpace;
	} else {
		freeSpace = 0;
	}
}

function setSizeOnCarousel(imgWidth, imgHeight, marginLeft, marginRight) {
	var leftWidth = freeSpace - marginLeft;
	if (($.browser.webkit) || (isIE8()) || (isIE7())) {
		leftWidth += 1;
	}
	$('#left_scroll').width(leftWidth);
	$('#prev').width(leftWidth);

	var rightLeftIndent = freeSpace + imgWidth + marginLeft + marginRight + marginRight;

	if ($.browser.webkit) {
		rightLeftIndent  = getRightLeftIndentForWebkit(rightLeftIndent, marginRight);
	}

	$('#right_scroll').css('left', rightLeftIndent + 'px');
	$('#next').css('left', rightLeftIndent + 'px');

	$('#carousel_ul').css('left', '-' + leftCarousel + 'px');
}

function getRightLeftIndentForWebkit(rightLeftIndent, marginRight) {
	// Dirty fix because of webkit error with different zoom
	var zoom = getZoom();
	var newRightLeftIndent = rightLeftIndent;
	if (zoom > 1) {
		newRightLeftIndent  = newRightLeftIndent - marginRight;
	}
	if (zoom < 0.8) {
		newRightLeftIndent = newRightLeftIndent - marginRight;
	}
	if (zoom < 0.7) {
		newRightLeftIndent = newRightLeftIndent - marginRight;
	}
	return newRightLeftIndent;
}

function getZoom(){ 
	var ovflwTmp = $('html').css('overflow');
	$('html').css('overflow','scroll');

	var viewportwidth = getWindowWidth();

	var windW = $(window).width();  
	var scrollBarW = viewportwidth - windW; 

	if (!scrollBarW) {
		return 1;
	}

	$('html').css('overflow',ovflwTmp);

	return  (15 / scrollBarW); 
}

function projectVideos() {
	$('.videos img').hover(function() {
		var rollOn = $(this).attr('data-rollOn');
		$(this).attr('src', rollOn);
	}, function() {
		var rollOut = $(this).attr('data-rollOut');
		$(this).attr('src', rollOut);
	});
}

function fixDisplayCellIE7() {
	if (isIE7()) {
		$(".tablecell").wrap("<td />");
		$(".tablerow").wrap("<tr />");
		$(".table").wrapInner("<table />");
		$("td").css("vertical-align", "middle");
		$(".gear-category-img").each(function() {
			$(this).parent().css('width', '165px');
		});
	}
}

