

$(document).ready(function() {
    blinkMenu();
	
    inquiryModal();
    contactModal();
	
    var isIE67 = ($.browser.msie && $.browser.version < 8 );
    if(isIE67){
        $('head').append('<link href="css/ie67.css" rel="stylesheet" type="text/css" />');
    }
	
    //attach facebook like button
    //attachFacebookLike();

    //Lazy load external script
    loadGoogleAnalytic();
    loadHistats();
});


function isIE6(){
    //IE6 haven't "document.body.style.maxHeight" function
    if(typeof document.body.style.maxHeight === "undefined")
        return true;
    else
        return false;
}

function blinkMenu(){
    var obj = $('.blink');
    
    setInterval(function(){
        $(obj).css('visibility','hidden');
    }, 1500);

    setInterval(function(){
        $(obj).css('visibility','visible');
    }, 600);
}

function inquiryModal(e){	
    $(".inquiryLink").fancybox({
        'width'			: 550,
        'height'		: '90%',
        'transitionIn'		: 'none',
        'transitionOut'		: 'none',
        'centerOnScroll'	: false,
        'autoDimensions'	: true,
        'autoScale'		: true,
        'type'			: 'iframe',
        'titleShow'		: false,
        'showCloseButton'	: true
    });
}

function contactModal(e){	
    $(".contactLink").fancybox({
        'width'			: 550,
        'height'		: 400,
        'transitionIn'		: 'none',
        'transitionOut'		: 'none',
        'centerOnScroll'	: false,
        'autoDimensions'	: true,
        'autoScale'		: true,
        'type'			: 'iframe',
        'titleShow'		: false,
        'showCloseButton'	: true
    });
}

/*function attachFacebookLike() {
	$('.facebook').click(function() {
		var url = $(this).attr('dref');
		url = url.replace('#{name}', encodeURIComponent(document.title));
		url = url.replace('#{url}', encodeURIComponent(window.location));
		window.open(url);
	});
}*/


/*******************************************************************************
 * Lazy load script 
 ******************************************************************************/
var googleAnalyticCode = "UA-5389106-1";
function loadGoogleAnalytic(){
    // determine whether to include the normal or SSL version
    var gaURL = (location.href.indexOf('https') == 0 ? 'https://ssl' : 'http://www');
    gaURL += '.google-analytics.com/ga.js';

    // include the script
    $.getScript(gaURL, function(){
        var pageTracker = _gat._getTracker(googleAnalyticCode);
        pageTracker._trackPageview();
    });
}

function loadHistats(){   
    var _Hasync= _Hasync|| [];
    _Hasync.push(['Histats.start', '1,309201,4,0,0,0,00010000']);
    _Hasync.push(['Histats.fasi', '1']);
    _Hasync.push(['Histats.track_hits', '']);
    (function() {
        var hs = document.createElement('script'); 
        hs.type = 'text/javascript'; 
        hs.async = true;
        hs.src = ('http://s10.histats.com/js15_as.js');
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(hs);
    })();
}

/*******************************************************************************
 * Search box function
 ******************************************************************************/
function submitSearchBox(){
    //alert('TODO, implement it please');    
    $('#searchForm').submit();
    return false;
    //TODO remove un selected vlaue from list and direct user to url
}
