// JavaScript Document

jQuery(function(){
				
	/**
	 * Handle the stats AJAX call when url address clicked
	 *
	 * Author: waldemarm
	 */	
	 $('.js_BuilderWWW').click(function(e){
		/** explode class names **/									
		$class_name_with_builder_id = $(this).attr('class').split(' ')[1];
		/** get builder id **/
		$builder_id = $class_name_with_builder_id.split('_')[2];
		saveStatistics('56',$builder_id);
	 });
	 
	 $('a.buttonGlobalEmail').click(function(e){
	        e.preventDefault();
	        e.stopPropagation();
			
	        /** create highslide object **/
	        hs.htmlExpand(this, {
				preserveContent: false, //disable iframe content caching					  
	            objectType: 'iframe',
	            width: 670,
	            objectHeight: 670,
	            objectLoadTime: 'after',
	            allowWidthReduction: 1,
	            showCredits: false,
	            dimmingOpacity: 0.70,
	            align: 'center'
	        }
	        );
	    })
	 
	/**
	 * Handle the default video/images display 
	 *
	 * Author: waldemarm
	 */	 
	 
	 /** check if we have cookie - if not then default set to images **/
	 if(_getCookie('profile_default_display')==null){
	 	_setCookie('profile_default_display','images');
	 }
	 
	$('.js_turnOnVideo').click(function(e){
		e.preventDefault();
		e.stopPropagation();										
		_setCookie('profile_default_display','video');
//		document.location.href = document.location.href+'?showvide=1';
		document.location.href = $(this).attr('href');
	});
	
	$('.js_turnOnImages').click(function(e){
		e.preventDefault();
		e.stopPropagation();
		_setCookie('profile_default_display','images');
//		document.location.href = document.location.href;		
		document.location.href = $(this).attr('href');		
	});	
	
	



		$('#rotating_images').cycle({
			fx: 'fade',
			timeout: 2500,
			requeueOnImageNotLoaded: true			
		});	


    $('#btnSubmitForm').click(function(e){
		e.preventDefault();
		e.stopPropagation(); 
        $('#askAQuestion').submit();
    });
	
	
				
    /**
     * ADD TO BOOKMARK
     *
     * Author: waldemarm
     **/
    $('#btnSignIn').click(function(e){
        e.preventDefault();
        e.stopPropagation();
		
        /** create highslide object **/
        hs.htmlExpand(this, {
			preserveContent: false, //disable iframe content caching					  
            objectType: 'iframe',
            width: 645,
            objectHeight: 585,
            objectLoadTime: 'after',
            allowWidthReduction: 1,
            showCredits: false,
            dimmingOpacity: 0.70,
            align: 'center'
        }
        );
    });

});


saveStatistics = function(log_type_id, ref_id_1, ref_id_2){

	$.ajax({
	   type: "GET",
	   url: "/stats/utility",
	   data: 'log_type_id='+log_type_id+'&ref_id_1='+ref_id_1+'&ref_id_2='+ref_id_2,
	   dataType: "html",	
	   processData: true,
	   success: function(returnedData){
	   }
	 });
};



/**
 * Function which set cookie with name, value and lifetime passed as the function parameter 
 * @param 'cookieLifetime' in default is set to 365 days
 *
 * Author: waldemar.matlosz
 */
function _setCookie(cookieName, cookieValue, cookieLifetime){
		if(isNaN(cookieLifetime)){
			cookieLifetime = 365;
		}
		$.cookie(cookieName, cookieValue, {path: '/', expires: cookieLifetime });
}

/**
 * Function which set cookie value of the selected cookie
 * @param 'cookieName' 
 *
 * Author: waldemar.matlosz
 */
function _getCookie(cookieName){
		return $.cookie(cookieName);
}



