﻿var Compare = {

	init : function() {

		var me = this;
		this.compare_top = document.getElementById('CompareHead_position');
		this.compare_head = document.getElementById('CompareHead');
		this.compare_head_fix = document.getElementById('CompareHead_fix');
		this.compare_models = document.getElementById('CompareModels');
		this.compare_view = document.getElementById('CompareView');
		this.compare_descr = document.getElementById('CompareDescr');
		this.compare_models_table = document.getElementById('CompareModels_table');

		if (this.compare_head_fix && this.compare_head)
		{
			this.compare_head_fix.style.height = this.compare_head.offsetHeight;
			window.onresize = function(){ me.fixed_head();  };
			window.onscroll = function(){ me.fixed_head_scroll();  };
			this.fixed_head();
		}
	},

	fixed_head : function() {					
			var width = $(this.compare_view).width();			
			this.compare_head.style.width = width + "px";		
	},
	
	fixed_head_scroll : function() {			
		if($(document).scrollTop() >= this.compare_top.offsetTop){
			this.compare_head.className = 'fixed';
			var width = $(this.compare_view).width();			
			this.compare_head.style.width = width + "px";
		}
		else
			this.compare_head.className = '';
	}
}

function goToCompare(e) {
    var val = GetCookie(CompareCookieName);
    if (val == null) {
        $.notifier("В сравнении нет товаров.", "success");  
        return false;
    }

    document.location = $("*[id$=hCompareUrl]").val() + val + "/";
}

function GetCookie(name) {
    var cookie = " " + document.cookie;
    var search = " " + name + "=";
    var setStr = null;
    var offset = 0;
    var end = 0;
    if (cookie.length > 0) {
        offset = cookie.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            end = cookie.indexOf(";", offset)
            if (end == -1) {
                end = cookie.length;
            }
            setStr = unescape(cookie.substring(offset, end));
        }
    }
    return (setStr);
}
