
$(document).ready(function() {
	comapre();
	
    $("img").tooltip({
        track: true,
        delay: 0,
        showURL: false,
        showBody: " - ",
        fade: 250
    });	
	
	$(".zoom").fancybox();    

	$('.title').tooltip();
	komunikat_dialog();
	
	/* regulamin i strona produktu */ 
	$(document).ready(function(){
		
		$(".iframe").fancybox({
					'width'				: 800,
					'height'			: 300,
					'autoScale'			: true,
					'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'type'				: 'iframe',
					'onClosed'			: function (){
					},
		});	
		
		$(".iAjax").fancybox({
			'autoScale'			: true,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'ajax',
			'onClosed'			: function (){
			},
		});	
		
		
		
	});
	
	if ($(".bookmarks").is('.bookmarks')) {
		$(".bookmarks").bookmark();
	}
});

/**
* Funkcja sprawdza ile jest tabel w div#compare i ustawia jego szerokość
*/
function comapre() {
	$('#compare').css('width', (160 + 16) * ($('#compare').find('table').length));
}

function komunikat_dialog() {
	
	$("#komunikat").dialog( {
		resizable : true,
		autoOpen : true,
		height : 'auto', 
		width : 400,
		minHeight : 40,
		open : function() {
		$("#komunikat").css( {
			'display' : 'block',
			'visibility' : 'visible'
		});
		$('object').hide();
	},
		close : function() {
			$('object').show();
		}
	});
}

function create_komunikat() {
	$("body").append("<div style='display:none;visibility:hidden;padding:20px; text-align: center; color: #2c2061' class='komunikat' id='komunikat' title='Komunikat'></div>");
}

var $m = {
		/**
		 * ======================================================
		 * @version 0.1
		 * @data 30-12-2008r.
		 * @see
		 * Obiekt ten pozwala uzyskac informacje o documencie.
		 * ======================================================
		 */
		$document : {
		    /**
		     * @namespace Scroll
		     * @version 0.1 beta
		     * @data 30-12-2008r.
		     * @param {String} xy
		     * @return
		     * Obiekt zwraca wartosc w "px" pozycje przewiniecia dokumentu.
		     */
		    Scroll: function(xy){
		        if (xy == 'y') {
		            if (window.pageYOffset != null) return window.pageYOffset;
		            else if (document.documentElement.scrollTop != null) return document.documentElement.scrollTop;
		        }
		        else if (xy == 'x') {
		            if (window.pageXOffset != null) return window.pageXOffset;
		            else if (document.documentElement.scrollLeft != null) return document.documentElement.scrollLeft;
		        }
		    },
		    
		    /**
		     * ======================================================
		     * @namespace WorkSpace
		     * @version 0.2 beta
		     * @data 30-12-2008r.
		     * @param {String} xy
		     * @return
		     * Obiekt zwraca wartosc w "px" wielkosc pola 
		     * roboczego kt�re widzi uzytkownik. Aby funkcja dzialala
		     * ======================================================
		     */
		    WorkSpace: function(xy){
				if (document.documentElement.clientHeight) {
					if (xy == 'y') { return document.documentElement.clientHeight; }
					else if (xy == 'x') { return document.documentElement.clientWidth; }
				} else if (window.innerHeight) {
					if (xy == 'y') { return window.innerHeight; }
					else if (xy == 'x') { return window.innerWidth; }
				}
		    }
		}
	};



/**
 * @author Mirosław Bogacz
 * @version 0.3 20-03-2009 12:29
 */
/**
 * ================================================================================================================
 * @param {Object} e
 * @namespace keyPress
 * @version 0.2 20-03-2009 13:24
 * Pozwala pobrać KOD wcieśniętego klawisza klawiatury.
 * Należy użyć przy zdażeniu przekazując parametr funkcji.
 * =================================================================================================================
 */
function keyPress(e){
    this.key = (window.event) ? window.event.keyCode : e.which;
    return this.key;
}

/**
 * ================================================================================================================
 * @param {Object} e
 * @namespace eventElement
 * @version 0.2 20-03-2009 13:24
 * Pozwala uzyskac informacje na temat elemntu nad którym jest kursor.
 * Należy użyć przy zdażeniu przekazując parametr funkcji.
 * =================================================================================================================
 */
function eventElement(e){
    this.e = (e) ? e : ((window.event) ? event : null)
    if (this.e.target) {
        this.eElement = e.target;
    }
    else if (window.event.srcElement) {
        this.eElement = window.event.srcElement;
    }
    return this.eElement;
}

/**
 * ================================================================================================================
 * @param {Object} Event
 * @param {Object} Func
 * @namespace eventWindow
 * @version 0.3 23-03-2009 10:54
 * Obiekt pozwala wykonac funkcje po zdarzeniu.
 * ================================================================================================================
 */
function eventWindow(Event, Func){
    if (window.addEventListener) {
        window.addEventListener(Event, Func, true);
    }
    else if (window.attachEvent) {
        window.attachEvent('on' + Event, Func)
    }
}

/**
 * ================================================================================================================
 * @param {Object} obj
 * @namespace InputValue
 * @version 0.1 30-03-2009 10:36
 * Obiekt sprawdza czy w polu input o podanym id została zmieniona wartuość jeżeli tak to nic się nie dzieje,
 * jeżeli nie została zmieniona przywraca domyślną wartość po zajściu zdarzenia onblur.
 * ================================================================================================================
 */
function inputValue(obj){
    obj.Input = obj.Input;
    obj.InputArray = new Array();
    
    for (var i = 0; i <= obj.Input.length; i++) {
        if (obj.Input[i] && document.getElementById(obj.Input[i])) {
            obj.InputArray[i] = document.getElementById(obj.Input[i]);
            obj.InputArray[i].defaultValue = document.getElementById(obj.Input[i]).value;
            obj.InputArray[i].onfocus = function(){
                if (this.value == this.defaultValue) {
                    this.value = '';
                }
            }
            obj.InputArray[i].onblur = function(){
                if (this.value == '') {
                    this.value = this.defaultValue;
                }
            }
        }
    }
}

function element(_Element, _Event, _Func){
    if (_Element.substring(0, 1) == '#') {
        this.Element = document.getElementById(_Element.substring(1, _Element.length));
        if (this.Element.addEventListener) {
            this.Element.addEventListener(_Event, _Func, false);
        }
        else if (this.Element.attachEvent) {
            this.Element.attachEvent('on' + _Event, _Func)
        }
    }
    else if (_Element.substring(0, 1) == '.') {
    
        this.Element = new Array();
        this.ElementLicznik = 0;
        
        for (var i = 0; i <= document.getElementsByTagName('*').length; i++) {
            if (document.getElementsByTagName('*')[i]) {
                if (document.getElementsByTagName('*')[i].className == _Element.substring(1, _Element.length)) {
                    this.Element[this.ElementLicznik] = document.getElementsByTagName('*')[i];
                    
                    this.ElementLicznik++;
                }
            }
        }
        
        for (var j = 0; j <= this.Element.length; j++) {
            if (typeof(this.Element[j]) != 'undefined') {
                if (this.Element[j].addEventListener) {
                    this.Element[j].addEventListener(_Event, _Func, false);
                }
                else if (this.Element[j].attachEvent) {
                    this.Element[j].attachEvent('on' + _Event, _Func)
                }
            }
        }
    }
}

function OpacityAnimation(o){
    o.element = o.element;
    o.elementBox = o.elementBox;
    o.start = o.start;
    o.end = o.end;
    o.time = o.time;
    o.speed = o.speed;
    o._Status = 'Stop';
    o._Element = document.getElementById(o.element);
    o._Animation = false;
    o._AnimationStan = 0;
    o._ElementBox = document.getElementById(o.elementBox);
    
    o.Start = function(){
        o.AnimationStatus();
    };
    
    o.Animation = function(){
        if (o._Status == 'Up' && o._AnimationStan < 100) {
            o._AnimationStan += o.speed;
        }
        else if (o._Status == 'Down' && o._AnimationStan > 0) {
            o._AnimationStan -= o.speed;
        }
        else if (o._AnimationStan == 0) {
            clearInterval(o._Animation);
            o._ElementBox.style.display = 'none';
            o._Status = 'Stop';
        }
        
        if (document.all) {
            o._ElementBox.style.filter = "alpha(opacity:" + o._AnimationStan + ")";
        }
        else {
            o._ElementBox.style.opacity = o._AnimationStan / 100;
        }
        
    };
    
    o.AnimationStatus = function(){
        o._Element.onmouseover = function(){
            if (o._Status == 'Stop') {
                o._Animation = setInterval(o.Animation, o.time);
                o.BoxPosition();
            }
            o._ElementBox.style.display = 'block';
            o._Status = 'Up';
        };
        
        o._Element.onmouseout = function(){
            o._Status = 'Down';
        };
    };
    
    o.BoxPosition = function(){
        o._ElementBox.style.top = (o._Element.offsetTop - 30) + 'px';
        o._ElementBox.style.left = (o._Element.offsetLeft + o._Element.offsetWidth) + 'px';
    };
    
    if (o._Element) {
        o.Start();
    }
}

/**
 * @namespace RovelImg
 * @version 0.9
 * @see
 */
var RovelImg = {
    start: function(){
        var e = document.getElementsByTagName('img');
        for (var i = 0; i < e.length; i++) {
            if (e[i].className.match(/([RovelImg])/gi) && e[i].src.match(/(_off.)/gi)) {
                RovelImg.over(e[i]);
                RovelImg.out(e[i]);
            }
        }
    },
    over: function(e){
        e.onmouseover = function() {
			this.style.width = this.offsetWidth + 'px';
			this.style.height = this.offsetHeight + 'px';
			this.style.background = 'url(' + this.src + ')';
            this.src = this.src.replace('_off.', '_on.');
        }
    },
    out: function(e){
        e.onmouseout = function(){
            this.src = this.src.replace('_on.', '_off.');
        }
    }
};



/* #################################################### */
eventWindow('load', function(){
    new element('.ListaZdjecie01', 'click', function(){
        element.style.border = '1px solid red';
    });
    /*AjaxHistory = new mAjaxHistory();*/
    RovelImg.start();
    new inputValue({
        Input: ['login', 'haslo']
    });
});


function Potwierdz(){
    var Usun = confirm("Potwierdz usunięcie konta")
    if (Usun) {
        apInnerSimple('kontener', 'ajax.php?tpl=koszyk', 'ajax=1&deleteKlient=1', 'usuwam konto...')
    }
}

function sklaujZdjecie(el, size){
    if (el.offsetWidth > size || el.offsetHeight > size) {
        if (el.offsetWidth > el.offsetHeight) {
            el.style.width = size + 'px';
        }
        else if (el.offsetWidth < el.offsetHeight) {
            el.style.height = size + 'px';
        }
        else {
        
            el.style.height = size + 'px';
            
        }
        
    }
    
}





function webDesktop(){
    var version = '0.1';
}

webDesktop.prototype.Window = function(Window){
    Window._type = Window._type;
    Window._title = Window._title;
    Window._titleMenu = Window._titleMenu;
    Window._content = Window._content;
    Window._height = Window._height;
    Window._width = Window._width;
    
    Window.Content = {
        myDiv: document.createElement('div'),
        
        create: function(){
            document.body.appendChild(this.myDiv);
            this.myDiv.className = 'webDesktopWindow';
        },
        
        get: function(){
            return this.myDiv
        },
        
        content: {
            myDiv: document.createElement('div'),
            
            create: function(){
                Window.Content.get().appendChild(this.myDiv);
                this.myDiv.className = 'webDesktopWindowContent';
            },
            
            get: function(){
                return this.myDiv;
            },
            
            content: function(){
                this.get().style.width = Window._width + 'px';
                this.get().style.height = Window._height + 'px';
                this.get().innerHTML = Window._content;
            },
            
            start: function(){
                this.create();
                this.content();
            }
        },
        
        title: {
            myDiv: document.createElement('div'),
            
            create: function(){
                Window.Content.get().appendChild(this.myDiv);
                this.myDiv.className = 'webDesktopWindowTitle';
            },
            
            get: function(){
                return this.myDiv;
            },
            
            start: function(){
                this.create();
            },
            
            text: {
                myDiv: document.createElement('div'),
                
                create: function(){
                    Window.Content.title.get().appendChild(this.myDiv);
                    this.myDiv.className = 'webDesktopWindowTitleText';
                    this.myDiv.innerHTML = Window._title;
                },
                
                get: function(){
                    return this.myDiv;
                },
                
                start: function(){
                    this.create();
                }
            },
            
            menu: {
                myDiv: document.createElement('div'),
                
                create: function(){
                    Window.Content.title.get().appendChild(this.myDiv);
                    this.myDiv.className = 'webDesktopWindowTitleMenu';
                },
                
                get: function(){
                    return this.myDiv;
                },
                
                button: {
                    minimize: {
                        myImg: document.createElement('img'),
                        
                        create: function(){
                            Window.Content.title.menu.get().appendChild(this.myImg);
                            this.myImg.src = 'tpl_front/tpl/webDesktop/minimize.gif';
                            this.myImg.title = 'Minimalizuj';
                        },
                        
                        get: function(){
                            return this.myImg;
                        },
                        
                        fun: function(){
                            this.myImg.onclick = function(){
                                if (Window.Content.content.get().style.display != 'none') {
                                    Window.Content.content.get().style.display = 'none';
                                }
                            }
                        },
                        
                        start: function(){
                            this.create();
                            this.fun();
                        }
                    },
                    
                    maximize: {
                        myImg: document.createElement('img'),
                        
                        create: function(){
                            Window.Content.title.menu.get().appendChild(this.myImg);
                            this.myImg.src = 'tpl_front/tpl/webDesktop/maximize.gif';
                            this.myImg.title = 'Maksymalizuj';
                        },
                        
                        get: function(){
                            return this.myImg;
                        },
                        
                        fun: function(){
                            this.myImg.onclick = function(){
                                if (Window.Content.content.get().style.display == 'none') {
                                    Window.Content.content.get().style.display = 'block';
                                }
                                else if (Window.Content.content.get().style.display != 'none' && Window.Content.get().offsetWidth != $m.$document.WorkSpace('x') + 2) {
                                    ResetWidth = Window.Content.get().offsetWidth;
                                    ResetHeight = Window.Content.get().offsetHeight;
                                    Window.Content.get().style.left = $m.$document.Scroll('x') + 'px';
                                    Window.Content.get().style.top = $m.$document.Scroll('y') + 'px';
                                    Window.Content.get().style.width = $m.$document.WorkSpace('x') + 'px';
                                    Window.Content.get().style.height = $m.$document.WorkSpace('y') + 'px';
                                }
                                else if (Window.Content.get().offsetWidth != ResetWidth) {
                                    Window.Content.get().style.width = ResetWidth + 'px';
                                    Window.Content.get().style.height = ResetHeight + 'px';
                                    Window.Content.get().style.left = $m.$document.Scroll('x') + ($m.$document.WorkSpace('x') / 2) - (Window.Content.get().offsetWidth / 2) + 'px';
                                    Window.Content.get().style.top = $m.$document.Scroll('y') + ($m.$document.WorkSpace('y') / 2) - (Window.Content.get().offsetHeight / 2) + 'px';
                                }
                            }
                        },
                        
                        start: function(){
                            this.create();
                            this.fun();
                        }
                    },
                    
                    close: {
                        myImg: document.createElement('img'),
                        
                        create: function(){
                            Window.Content.title.menu.get().appendChild(this.myImg);
                            this.myImg.src = 'tpl_front/tpl/webDesktop/close.gif';
                            this.myImg.title = 'Zamknij okno';
                        },
                        
                        get: function(){
                            return this.myImg;
                        },
                        
                        fun: function(){
                            this.myImg.onclick = function(){
                                document.body.removeChild(Window.Content.get());
                                document.body.removeChild(document.getElementById('MASK2'));
                            }
                        },
                        
                        start: function(){
                            this.create();
                            this.fun();
                        }
                    },
                    
                    start: function(){
                        if (Window._titleMenu != undefined) {
                            if (Window._titleMenu[0] == 1) {
                                this.minimize.start();
                            }
                            if (Window._titleMenu[1] == 1) {
                                this.maximize.start();
                            }
                            if (Window._titleMenu[2] == 1) {
                                this.close.start();
                            }
                        }
                    }
                },
                
                start: function(){
                    this.create();
                }
            }
        },
        
        start: function(){
            this.create();
            this.title.start();
            this.title.text.start();
            this.title.menu.start();
            this.title.menu.button.start();
            this.content.start();
            this.get().style.left = $m.$document.Scroll('x') + ($m.$document.WorkSpace('x') / 2) - (this.get().offsetWidth / 2) + 'px';
            this.get().style.top = $m.$document.Scroll('y') + ($m.$document.WorkSpace('y') / 2) - (this.get().offsetHeight / 2) + 'px';
            MASK = document.createElement('div');
            MASK.id = 'MASK2';
            MASK.className = 'MASK2';
            document.body.appendChild(MASK);
            
            if (window.innerWidth || window.innerHeight) {
                if (!document.documentElement.scrollHeight < document.body.offsetHeight) {
                    MASK.style.width = document.body.offsetWidth + 'px';
                    MASK.style.height = (document.documentElement.scrollHeight - document.body.offsetHeight) + document.body.offsetHeight + 'px';
                    
                }
                else {
                    MASK.style.width = document.body.offsetWidth + 'px';
                    MASK.style.height = document.body.offsetHeight + 'px';
                }
            }
            else {
                if (document.documentElement.clientHeight < document.documentElement.scrollHeight) {
                    MASK.style.width = document.body.clientWidth + 'px';
                    MASK.style.height = (document.documentElement.scrollHeight - document.documentElement.clientHeight) + document.body.clientHeight + 'px';
                    
                }
                else {
                    MASK.style.width = document.body.clientWidth + 'px';
                    MASK.style.height = document.body.clientHeight + 'px';
                }
            }
			
		      $("#MASK2").animate({ 
		        opacity: 0.5
		      }, 1500 );
			  $(".webDesktopWindow").animate({ 
		        opacity: 1
		      }, 1500 );
        }
    }
    
    
    Window.Content.start();
    
};
Sugester = {}

Sugester.Engine = function(setup){
    var Engine = {
   			
        version: '0.1',
        url: 'http://www.interopony.pl/tpl_front/tpl/img/',
        
        Interface: {
            btnBar: {
                gfx: 'sugester-navigate-start.gif',
                html: document.createElement('img'),
                add: function(){
                    var that = this;
                    document.body.appendChild(that.get())
                    that.get().id = 'sugesternavigatestart'
                    that.get().onload = function(){
                        that.get().style.position = 'absolute';
                       
						$(document).ready(function() {
					    $(that.get()).css("position", "absolute");
						});
						$(that.get()).css("top", $(window).scrollTop() + (($m.$document.WorkSpace('y') / 2) - that.get().offsetHeight / 2) + "px");
						$(window).scroll(function() {
						    $(that.get()).css("top", $(window).scrollTop() + (($m.$document.WorkSpace('y') / 2) - that.get().offsetHeight / 2) + "px");
						});
                        that.get().style.left = $m.$document.WorkSpace('x') - that.get().offsetWidth + 'px';
                        that.get().style.cursor = 'pointer';
                    }
                    
                    that.get().src = Engine.url + that.gfx;
                    that.get().onclick = that.action;
                },
                get: function(){
                    var that = this;
                    return that.html;
                },
                action: function(){
                    setup.action();
                }
            }
        }
    
    };
    
    Engine.Interface.btnBar.add();
    return Engine;
};

function Compare()
{
	var Compare, that;
	
	Compare = {
		init: function() {
		
		},
		
		add: function(id, element) {
			if ($(element).parent().find('.add').is('.add') && $(element).parent().find('.remove').is('.remove')) {
				$(element).parent().find('.add').hide();
				$(element).parent().find('.remove').show();
			}
			$.post('porownaj.php', {'add': id}, function(data) {
				if (data == true) {

				}
			});
		},
		
		remove: function(id, element) {
			if ($(element).parent().find('.add').is('.add') && $(element).parent().find('.remove').is('.remove')) {
				$(element).parent().find('.add').show();
				$(element).parent().find('.remove').hide();
			}
			$.post('porownaj.php', {'remove': id}, function(data) {
				if (data == true) {
					
				}
			});
		}
	};
	
	that = Compare;
	that.init();
	return that;
}

