


//-----------------------------------------------------------------------------------------
// Test if current object is in the screen, only in horizontal direction
//-----------------------------------------------------------------------------------------
// parameters : offsetCoeff : offset coeff (0: none, > 0: N tileq to the right, < 0: N tile to the left)     
//---------------------------------------------------------------------------------------
// return true if current object is in the screen, false in other cases
//-----------------------------------------------------------------------------------------
$.fn.isOnHorizontalScreen = function (offsetCoeff) {

    var win = $(window);

    var viewport = {
        top: win.scrollTop(),
        left: win.scrollLeft()
    };
	
	var winWidth =  $(".homeCarousels").width();
    viewport.right = viewport.left + winWidth;
    
    var bounds = $(this).offset();
    var width = $(this).outerWidth();

    bounds.right = bounds.left + width;
    bounds.right += width * offsetCoeff;
    bounds.left += width * offsetCoeff;
   
    return (!(viewport.right < bounds.right || viewport.left > bounds.left));

};


$.fn.isOnHorizontalParent = function (offsetCoeff, aParent) {
    
    var bounds = $(this).offset();
    var width = $(this).outerWidth();

	var boundsParent = $(aParent).offset()
	var widthParent = aParent.width();

    bounds.right = bounds.left + width;
    bounds.right += width * offsetCoeff;
    bounds.left += width * offsetCoeff;
    return (!(boundsParent.left + widthParent < bounds.right || boundsParent.left > bounds.left));
};

//-----------------------------------------------------------------------------------------
// load templates in files and add it in the current document 
// if the loading operation fail an exception is fire
//-----------------------------------------------------------------------------------------
// parameters : templatePath : templates path
//              templateList :  template name list
//              success : all loading success callback 
//---------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------
$.fn.loadTemplates = function (templatePath, templateList, success) {

    var loadedCount = 0;

    $.each(templateList, function (i, templateName) {
        var templateFile = templatePath + '/' + templateName + '.tmpl.html';
        $.get(templateFile, function (template) {
            $("body").append("<script id=\"" + templateName + "\" type=\"text/html\">" + template + "<\/script>");
            loadedCount++;
            if (templateList.length == loadedCount) {
                success();
            }
        }).fail(function () {
            throw 'Err on loading this template : ' + templateFile;
        });
    });
};

$.fn.getIEVersion = function getIEVersion() {
    var uAgent = window.navigator.userAgent;
	return 11;
	if (uAgent.indexOf('Edge/') > -1) {
	    return 12;                       // IE 12 +  
	} 
	else if ((uAgent.indexOf("Trident/7.0") > -1) || (uAgent.indexOf("Trident/8.0") > -1)) {
		if ((uAgent.indexOf("MSIE 7.0") > -1) || (uAgent.indexOf('rv:'))) {
			return 11;                  // IE 11
		}
	}
	else if (uAgent.indexOf("Trident/6.0") > -1) {
		if ((uAgent.indexOf("MSIE 7.0") > -1) || (uAgent.indexOf("MSIE 10.0") > -1)) {
			return 10;                  // IE 10
		}
	}
	else if (uAgent.indexOf("Trident/5.0") > -1) {      
		if ((uAgent.indexOf("MSIE 7.0") > -1) || (uAgent.indexOf("MSIE 9.0") > -1)) {
			return 9;                   // IE 9
		}
	}
	else if (uAgent.indexOf("Trident/4.0") > -1) {
		if ((uAgent.indexOf("MSIE 7.0") > -1) || (uAgent.indexOf("MSIE 8.0") > -1)) {
			return 8;                   // IE 8
		}
	}
	else if (uAgent.indexOf("MSIE 7.0") > -1)
		return 7;                       // IE 7
	else if (uAgent.indexOf("MSIE 6.0") > -1)
		return 6;                       // IE 6	
	
}

$(window).resize(function() {
	switch (true) {
	  case ($(".canvas").width() < 831):
		$(".content_pages .homeCarousels").css({
				"width": "100%"
			});	
		$(".content_pages .actuFeed").css({
				"width": "100%",
				"float": "left"
			});
		$(".actuFeed ul li.actuFeedItem").css({
				 "display": "inline-block",
				 "margin":"0px 20px 20px 0px"
		});
		break;
	 default:
		$(".content_pages .homeCarousels").width($(".canvas").width() - 370);
		$(".content_pages .actuFeed").css({
				"width": "280px",
				"height": "auto",
				"float": "right",
				"min-width": "250px"
			});
		$(".actuFeed ul li.actuFeedItem").css({
				"display": "block",
				"width": "280px",
				"height": "120px",
				"margin": "0px 0px 20px 0px"
		});			
		break;		
	}
});
	
