
$(document).ready(function(){
	InitializeFontSize();
	InitializeCufon();
	
	// font size management
	$('#font-size-small').click(function(){ ApplyFontSize(1, true); });
	$('#font-size-large').click(function(){ ApplyFontSize(2, true); });
	
	// location image popups
	$('div.location-images div.image img').mouseover(function(){
		$('#image-popup').css('width', $(this).attr('rel-width') + 'px');
		$('#image-popup').css('height', $(this).attr('rel-height') + 'px');
		$('#image-popup').css('margin-left', '-' + (parseInt($(this).attr('rel-width'))/2) + 'px');
		$('#image-popup').css('margin-top', '-' + (parseInt($(this).attr('rel-height'))/2) + 'px');
		$('#image-popup').html('<img src="' + $(this).attr('rel-large') + '" border="0" />');
		$('#image-popup').show();
		$('#image-popup img').click(function() { $('#image-popup').hide(); });
	});
	$('div.location-images div.image img').mouseout(function(){ $('#image-popup').hide(); });
	$('#image-popup').mouseover(function() { $('#image-popup').show(); });
	$('#image-popup').mouseout(function() { $('#image-popup').hide(); });
});


function InitializeCufon() {
	Cufon.replace(['.top_nav li'], {fontFamily: 'Helvetica Neue LT Std',hover: true});
	Cufon.replace(['.banner_text h2'], {fontFamily: 'Myriad Pro',hover: true});
	Cufon.replace(['.know_more','.box h3','.latest_news h4','.block-left h4','.special_links h4','.contact_us h4','.newsletter h4','#mid_container h1','#mid_container h2','#mid_container h3'], {fontFamily: 'Myriad Pro Regular',hover: true});
	Cufon.replace(['button.btn span'], {fontFamily: 'Myriad Pro Semi Bold',hover: true});
}

function InitializeFontSize() {
	if (GetFontSizeFromCookie() == 2)
		ApplyFontSize(2, false);
}

function GetFontSizeFromCookie() {
	try
	{
		var fontSizeNr = jQuery.cookie('iszFontSizeNumber');
		if (fontSizeNr.length > 0)
			return parseInt(fontSizeNr);
	} catch(ex) { }
	return 1;
}

function SetFontSizeToCookie(fontSizeNr) {
	jQuery.cookie('iszFontSizeNumber', fontSizeNr);
}

function ApplyFontSize(fontSizeNr, applyCufon) {
	SetFontSizeToCookie(fontSizeNr);
	
	$('#font-size-small').removeClass('active');
	$('#font-size-large').removeClass('active');
	
	if (fontSizeNr == 1) { // small
		$('#font-size-small').addClass('active');
		
		$('body').css('font-size', '11px');
		$('#product_box_container .box ul li').css('font-size', '13px');
		$('#header ul li').css('font-size', '12px');
		$('ul.top_nav li a').css('font-size', '15px');
	}
	if (fontSizeNr == 2) { // large
		$('#font-size-large').addClass('active');
		
		$('body').css('font-size', '14px');
		$('#product_box_container .box ul li').css('font-size', '15px');
		$('#header ul li').css('font-size', '14px');
		$('ul.top_nav li a').css('font-size', '18px');
	}
	if (applyCufon)
		InitializeCufon();
}




jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

