/*—~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ M A I N.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

var mainClass = {

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ VARIABLES.
	cacheImage: [],

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ INITIALIZE.
	initialize: function() {
		// Layout.
		this.detectMobile();
		this.listTokenRemove();
		this.googleAnalyticsInit();
		// Init.
		this.pageInit();
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DETECT MOBILE DEVICES.
	detectMobile: function() {
		var userAgent = navigator.userAgent.toLowerCase();
		if ((userAgent.search(/android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris/i) != -1) || (userAgent.search(/kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)|plucker|pocket|psp/i) != -1) || (userAgent.search(/symbian|treo|up.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i) != -1))
			this.isMobile = true;
		else
			this.isMobile = false;
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GOOGLE ANALYTICS.
	googleAnalyticsInit: function() {
		var apiHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
		$.getScript(apiHost + "google-analytics.com/ga.js", function() {
			var pageTracker = _gat._getTracker("UA-19601632-1");
			pageTracker._initData();
			pageTracker._trackPageview();
		});
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TINY-URL.
	urlTinyGenerate: function(url, success) {
		$.ajax({
			url: "siteData.php",
			dataType: "json",
			data: {
				xhrAct: "getUrlTiny",
				url: url
			},
			success: function(data) {
				success && success(data.urltiny);
			}
		});
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PRELOAD IMAGES.
	preLoadImage: function() {
		var argsCount = arguments.length;
		for (var i=argsCount; i--;) {
			var imgObj = document.createElement('img');
			imgObj.src = arguments.length[i];
			mainClass.cacheImage.push(imgObj);
		}
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ROLL-OVER IMAGES.
	rolloverImage: function() {
		$('img[src*=-out], input[src*=-out]').each(function(i) {
			var imgSrc = $(this).attr('src');
			var imgPath = imgSrc.substring(0, imgSrc.lastIndexOf('-'));
			var imgExtension = imgSrc.substr(imgSrc.lastIndexOf('.'));
			mainClass.preLoadImage(imgPath+"-over"+imgExtension);
			$(this).bind({
				mouseenter: function() {
					$(this).attr('src', imgPath+"-over"+imgExtension);
				},
				mouseleave: function() {
					$(this).attr('src', imgPath+"-out"+imgExtension);
				}
			});
		});
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MENU LIST TOKEN.
	listTokenRemove: function() {
		$('li:last-child').each(function(i) {
			if ($(this).css('backgroundImage').search(/bullet/i) == -1)
				($(this).css('float') == "right") ? $(this).css({paddingLeft:"0px"}) : $(this).css({paddingRight:"0px", backgroundImage:"none"});
		});
		$('li:first-child').each(function(i) {
			if ($(this).css('backgroundImage').search(/bullet/i) == -1)
				($(this).css('float') == "right") ? $(this).css({paddingRight:"0px", backgroundImage:"none"}) : $(this).css('padding-left', "0px");
		});
	},


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C O N T E N T   P A G E.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ INIT.
	pageInit: function() {
		$('a#logoAnchor').html("QUI<span id=\"logoHyphen\">*</span>DESIGN<span id=\"logoTld\">.fr</span>");
		$('a').attr('target', "_blank");
		$('a#contactEmailAnchor').attr('href', "mailto:webmaster@qui-design.fr");
		$('a#contactLiveAnchor').attr('href', "msnim:chat?contact=msn@qui-design.fr");
		$('a#contactGtalkAnchor').attr('href', "gtalk:chat?jid=qui-design@gmail.com");
	}

};



/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ O N   D O M   R E A D Y.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
jQuery(document).ready(function() {
	mainClass.initialize();
});
