var IE = /*@cc_on!@*/false;
var IE6 = (IE && (navigator['appVersion'].indexOf('MSIE 6') > 0)) ? true : false;

var site = function() {

    $(document).ready(function() {
        site.initialize();
    });

    $(window).load(function() {
    });

    return {

        scrolllist: function(id) {
            if ($('div#' + id).attr('ua') != 'true') {
                site.scrolllistanim(id, 'top', 500)
            }
            setTimeout(function() { site.scrolllist(id) }, 2500);
        },

        scrolllistanim: function(id, direction, duration) {
            var that = $('div#' + id + ' div.inner');
            if (that.attr('locked') != 'true') {
                if (direction == 'top') {
                    that.attr('locked', 'true');
                    that.find('ul:first').append('<li>' + that.find('ul > li:first')[0].innerHTML + '</li>');
                    that.animate(
						{ top: String(parseInt(that.css('top')) - that.find('ul:first > li:first').innerHeight()) + 'px' },
						duration,
						'linear',
						function() {
						    that.find('ul:first > li:first').remove();
						    that.css({ 'top': '0px' });
						    that.attr('locked', 'false');
						}
					);
                } else if (direction == 'bottom') {
                    that.attr('locked', 'true');
                    that.find('ul:first').prepend('<li>' + that.find('ul > li:last')[0].innerHTML + '</li>');
                    that.css({ 'top': String(parseInt(that.css('top')) - that.find('ul:first > li:first').innerHeight()) + 'px' });
                    that.animate(
						{ top: '0px' },
						duration,
						'linear',
						function() {
						    that.find('ul:first > li:last').remove();
						    that.css({ 'top': '0px' });
						    that.attr('locked', 'false');
						}
					);
                }
            }
        },

        progthumbsanim: function(id, direction, duration) {
            var that = $('div#' + id + ' div.inner');
            if (that.attr('locked') != 'true') {
                if ((direction == 'left') && (that.position().left + that.innerWidth() - that.parents('div.outer').innerWidth() > 0)) {
                    that.attr('locked', 'true');
                    that.animate(
						{ left: String(that.position().left - that.find('div.item').innerWidth()) + 'px' },
						duration,
						'linear',
						function() {
						    that.attr('locked', 'false')
						}
					);
                } else if ((direction == 'right') && (parseInt(that.css('left')) < 0)) {
                    that.attr('locked', 'true');
                    that.animate(
						{ left: String(that.position().left + that.find('div.item').innerWidth()) + 'px' },
						duration,
						'linear',
						function() {
						    that.attr('locked', 'false')
						}
					);
                }
            }
        },

        latestnewsanim: function() {
            var that = $('div#ucNewsTicker_divLatestNews div.inner');
            that.append('<p>' + that.find('p:first')[0].innerHTML + '</p>');
            that.animate(
				{ left: (0 - that.find('p:first').innerWidth()) + 'px' },
				that.find('p:first').innerWidth() * 15,
				'linear',
				function() {
				    that.find('p:first').remove();
				    that.css({ 'left': '0px' });
				    setTimeout(function() { site.latestnewsanim() }, 2345);
				}
			);
        },

        suggestionanim: function() {
            var that = $('div#suggestion div.list');
            var i = parseInt(that[0].className.split('tab')[1]);
            i = i % that.find('div.box').length + 1;
            that[0].className = 'list list_suggest tab' + i;
            site.suggestiontimer = setTimeout(function() { site.suggestionanim() }, Math.max(1000, parseInt(that.find('div.box:visible')[0].className.split('delay')[1]) * 1000));
        },



        initialize: function() {
            /* article ads */
            if ($('div#divBannerNewsPageContentTop').find('img, object, iframe').length <= 0) {
                $('div#divBannerNewsPageContentTop').parent().hide();
            }

            if ($('div#divBannerNewsPageContentBottom').find('img, object, iframe').length <= 0) {
                $('div#divBannerNewsPageContentBottom').parent().hide();
            }
            /* /article ads */

            /* side ads */
            if ($('div#divBannerLeft_1u').find('img, object, iframe').length <= 0) {
                if ($('div#divBannerLeft_1u').parent().hasClass('banner')) {
                    $('div#divBannerLeft_1u').parent().hide();
                }
                $('div#divBannerLeft_1u').hide();
            }
            /* /side ads */


            /* google ad */
            if ($('div#divBannerNewsPageContentBottom').find('img, object, iframe').length <= 0) {
                $('div#googleads468x60').append('<iframe frameborder="0" scrolling="no" src="/Premier/google_ads/468x60.html" style="width: 468px; height: 60px; overflow: hidden; background: #fff;"></iframe>');
            }
            else {
                $('div#googleads468x60').parent().hide();
            }

            if ($('div#divBannerLeft_1u').find('img, object, iframe').length <= 0) {
                $('div#googleads120x240').append('<iframe frameborder="0" scrolling="no" src="/Premier/google_ads/120x240.html" style="width: 120px; height: 240px; overflow: hidden; background: #fff;"></iframe>');
            }
            else {
                $('div#googleads120x240').parent().hide();
            }            
            /* /google ad */



            var tmp = null;

            // common settings
            $('a._blank').click(function() {
                window.open(this.href);
                this.blur();
                return false;
            });

            if (document.body.className == 'main') {
                $('div.cont div.scrolllist').height($('div#progthumbs').height() - 1);
            } else {
                $('div.cont div.content div.feature div.scrolllist').height($('div.cont div.content div.feature div.list').height() - 14);
            }

            $('div.tabsheet h4 a').click(function() {
                var ts = $(this).parents('div.tabsheet');
                for (var i = 0; i <= ts.find('div.sheet').length; i++) {
                    ts[0].className = ts[0].className.split('tab' + String(i)).join('');
                }
                ts[0].className += ' ' + $(this).parent()[0].className;
                this.blur();
                return false;
            });

            $('div#progs').click(function() {
                $(this).toggleClass('progs_close');
                $('div#proglist').toggleClass('visible');
            });



            $('div.scrolllist').each(function(i) {
                if ($(this).find('div.inner').innerHeight() > $(this).innerHeight()) {
                    if (!$(this).attr('id')) {
                        $(this).attr('id', 'scrolllist' + i);
                    }
                    eval('setTimeout(function(){site.scrolllist(\'' + $(this).attr('id') + '\')}, ' + parseInt(Math.random() * 666 + 1500) + ')');
                    $(this)
					.hover(
						function() {
						    $(this).attr('ua', 'true');
						},
						function() {
						    $(this).attr('ua', 'false');
						}
					)
					.find('div.top a').click(function() {
					    site.scrolllistanim($(this).parents('div.scrolllist').attr('id'), 'bottom', 100);
					    this.blur();
					    return false;
					})
					.end()
					.find('div.bot a').click(function() {
					    site.scrolllistanim($(this).parents('div.scrolllist').attr('id'), 'top', 100);
					    this.blur();
					    return false;
					});
                } else {
                    $(this).find('div.top a, div.bot a').click(function() {
                        this.blur();
                        return false;
                    });
                }
            });

            $('div#progthumbs div.ch').each(function(i) {
                $(this).find('div.inner').css({ 'left': '-' + String(Math.max(0, Math.min($(this).find('div.item').length - 3, parseInt($(this)[0].className.split(' n')[1]))) * $(this).find('div.item').innerWidth()) + 'px', 'width': String($(this).find('div.item').length * $(this).find('div.item').innerWidth()) + 'px' });
                if (!$(this).attr('id')) {
                    $(this).attr('id', 'progthumbsch' + i);
                }
                $(this)
				.find('div.item').each(function() {
				    $(this).append('<strong class="shadow">' + $(this).find('strong').html() + '</strong>');
				})
				.end()
				.find('div.left a').click(function() {
				    site.progthumbsanim($(this).parents('div.ch').attr('id'), 'right', 100);
				    this.blur();
				    return false;
				})
				.end()
				.find('div.right a').click(function() {
				    site.progthumbsanim($(this).parents('div.ch').attr('id'), 'left', 100);
				    this.blur();
				    return false;
				});
            });

            if ($('div#ucNewsTicker_divLatestNews').length > 0) {
                site.latestnewstimer = setTimeout(function() { site.latestnewsanim() }, 2345);
            }

            if ($('div#suggestion').length > 0) {
                tmp = '<div class="paging">';
                for (var i = 1; i <= $('div#suggestion div.list div.box').length; i++) {
                    tmp += '<div class="tab' + String(i) + '"></div>';
                }
                tmp += '</div>';
                $('div#suggestion div.list').append(tmp);
                $('div#suggestion div.list div.box').each(function(i) {
                    $(this).addClass('tab' + String(i + 1));
                });
                $('div#suggestion div.list')[0].className = 'list list_suggest tab1';
                site.suggestiontimer = setTimeout(function() { site.suggestionanim() }, Math.max(1000, parseInt($('div#suggestion div.list div.box:visible')[0].className.split('delay')[1]) * 1000));
                $('div#suggestion div.paging div').click(function() {
                    clearInterval(site.suggestiontimer);
                    $('div#suggestion div.list')[0].className = 'list list_suggest ' + $(this)[0].className;
                    site.suggestiontimer = setTimeout(function() { site.suggestionanim() }, Math.max(1000, parseInt($('div#suggestion div.list div.box:visible')[0].className.split('delay')[1]) * 1000));
                });
            }

            /* page tools */
            $('div.article div.pagetools a.pageforward').click(function() {
                $(this).parents('div.pagetools').find('div.pageforward').toggleClass('hidden')
                $(this).blur();
            });
            $('div.article div.pagetools div.pageforward div.button input.cancel').click(function() {
                $(this).parents('div.pageforward').toggleClass('hidden');
            });
            /* /page tools */

            /* header banner */
            if ($('div.head div.HeaderBanner').find('img, object, iframe').length > 0) {
                $('div.head div.HeaderBanner').show();
                $('div.head h1').show();
                if ($('div.head div.banner932x152').length <= 0) {
                    $('div.head div.HeaderBanner').css({ 'margin-bottom': '-40px' });
                }
            } else {
                if (document.body.className != 'main') {
                    if ($('div.head div.banner932x152').length > 0) {
                        $('div.head h1').hide();
                    } else {
                        $('div.head h1').show();
                    }
                }
            }
            /* /header banner */
            /* side banner */
            $('div.side div.banner').each(function() {
                if ($(this).find('img, object, iframe').length > 0) {
                    $(this).show();
                }
            });
            /* /side banner */

        },



        sethomepage: function(obj, url) {
            if (IE && window.external) {
                obj.style.behavior = 'url(#default#homepage)';
                obj.setHomePage(url);
            } else {
                alert('A kezdőlap beállításához az URL bar-ban lévő ikont a házikó ikonra kell húzni!');
            }
        }



    }

} ();




var TextSizer = function () {
	var container = new Array();	
	container.push('div.article');
	var size;			
	$(document).ready(function(){
		size = parseInt($('div.article').css('fontSize'),10);					
		$('a.textincrease').click(TextSizer.increase);
		$('a.textdecrease').click(TextSizer.decrease);
	});			
	return {
		increase: function(e){
			size++;
			for (var i = 0; i < container.length; i++) {
				$(container[i])[0].style.fontSize = size + 'px';
			}
		},
		decrease: function(e){
			size--;
			for (var i = 0; i < container.length; i++) {
				$(container[i])[0].style.fontSize = size + 'px';
			}
		}
	}
}();



var Print =  function () {
	var printbar = ['<div id="PrintBar" style="display:none;"><p>',document.getElementsByTagName('title')[0].innerHTML,' <small>nyomtatható változat</small>','</p><button id="PrintCancel">Mégse</button><button id="PrintPrint">Nyomtatás</button></div>'].join('');
	var setActiveStyleSheet = function(title) {  // select the stylesheet
		var i, a, main;
		for (i=0; (a = document.getElementsByTagName("link") [i]); i++) {
			if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
				a.disabled = true;
				if (a.getAttribute("title") == title) a.disabled = false;
			}
		}
	}

	$(document).ready(function() {
		$('body').append(printbar);
		$('#PrintPrint').click(Print.print);
		$('#PrintCancel').click(Print.cancel);
		$('div.pagetools a.print').click(function(e){
			Print.preview();
		});
	});		
		
	return {
		preview: function () {
			window.scrollTo(0,0);
			setActiveStyleSheet("printscreen");
			$('div#PrintBar').show();
		},
		print: function () {
			window.print();
			Print.cancel();
		}, 
		cancel: function () {
			$('div#PrintBar').hide();
			setActiveStyleSheet("default");
		}
	};			
}();



/**
var colorchange =  function () {
	$(document).ready(function(){
		var cn = '';
		if (document.body.className.indexOf('main') >= 0) {
			cn = 'main';
		}
		var ih = $('<div class="colorchange" style="position: absolute; left: 0px; top: 0px; background: #000; z-index: 999;">' +
							 '<a href="#" onclick="document.body.className = \'' + cn + ' red\'; return false;">red</a><br />' + 
							 '<a href="#" onclick="document.body.className = \'' + cn + ' black\'; return false;">black</a><br />' +
							 '<a href="#" onclick="document.body.className = \'' + cn + ' blue\'; return false;">blue</a><br />' +
							 '<a href="#" onclick="document.body.className = \'' + cn + ' brown\'; return false;">brown</a><br />' +
							 '<a href="#" onclick="document.body.className = \'' + cn + ' green\'; return false;">green</a><br />' +
							 '<a href="#" onclick="document.body.className = \'' + cn + ' purple\'; return false;">purple</a><br />' +
							 '<a href="#" onclick="document.body.className = \'' + cn + ' white\'; return false;">white</a><br />' +
							 '<a href="#" onclick="document.body.className = \'' + cn + ' yellow\'; return false;">yellow</a>' +
							 '</div>');
		$('body').append(ih);
 });
}();
/**/
