
;(function($){ // secure $ jQuery alias
/*******************************************************************************************/	
// jquery.event.drag.js - rev 10
// Copyright (c) 2008, Three Dub Media (http://threedubmedia.com)
// Liscensed under the MIT License (MIT-LICENSE.txt)
// http://www.opensource.org/licenses/mit-license.php
// Created: 2008-06-04 | Updated: 2008-08-05
/*******************************************************************************************/
// Events: drag, dragstart, dragend
/*******************************************************************************************/

// jquery method
$.fn.drag = function( fn1, fn2, fn3 ){
	if ( fn2 ) this.bind('dragstart', fn1 ); // 2+ args
	if ( fn3 ) this.bind('dragend', fn3 ); // 3 args
	return !fn1 ? this.trigger('mousedown',{ which:1 }) // 0 args
		: this.bind('drag', fn2 ? fn2 : fn1 ); // 1+ args
	};

// special event configuration
var drag = $.event.special.drag = {
	distance: 0, // default distance dragged before dragstart
	setup: function( data ){
		data = $.extend({ distance: drag.distance }, data || {});
		$.event.add( this, "mousedown", drag.handler, data );
		},
	teardown: function(){
		$.event.remove( this, "mousedown", drag.handler );
		if ( this == drag.dragging ) drag.dragging = drag.proxy = null; // deactivate element
		selectable( this, true ); // enable text selection
		},
	handler: function( event ){ 
		var returnValue;
		// mousedown has initialized
		if ( event.data.elem ){ 
			// update event properties...
			event.dragTarget = event.data.elem; // source element
			event.dragProxy = drag.proxy || event.dragTarget; // proxy element or source
			event.cursorOffsetX = event.data.x - event.data.left; // mousedown offset
			event.cursorOffsetY = event.data.y - event.data.top; // mousedown offset
			event.offsetX = event.pageX - event.cursorOffsetX; // element offset
			event.offsetY = event.pageY - event.cursorOffsetY; // element offset
			}
		// handle various events
		switch ( event.type ){
			// mousedown, left click
			case !drag.dragging && event.which==1 && 'mousedown': // initialize drag
				$.extend( event.data, $( this ).offset(), { 
					x: event.pageX, y: event.pageY, elem: this, 
					dist2: Math.pow( event.data.distance, 2 ) //  x² + y² = distance²
					}); // store some initial attributes
				$.event.add( document.body, "mousemove mouseup", drag.handler, event.data );
				selectable( this, false ); // disable text selection
				return false; // prevents text selection in safari 
			// mousemove, check distance, start dragging
			case !drag.dragging && 'mousemove': // DRAGSTART >>	
				if ( Math.pow( event.pageX-event.data.x, 2 ) 
					+ Math.pow( event.pageY-event.data.y, 2 ) //  x² + y² = distance²
					< event.data.dist2 ) break; // distance tolerance not reached
				drag.dragging = event.dragTarget; // activate element
				event.type = "dragstart"; // hijack event
				returnValue = $.event.handle.call( drag.dragging, event ); // trigger "dragstart", return proxy element
				drag.proxy = $( returnValue )[0] || drag.dragging; // set proxy
				if ( returnValue !== false ) break; // "dragstart" accepted, stop
				selectable( drag.dragging, true ); // enable text selection
				drag.dragging = drag.proxy = null; // deactivate element
			// mousemove, dragging
			case 'mousemove': // DRAG >> 
				if ( drag.dragging ){
					event.type = "drag"; // hijack event
					returnValue = $.event.handle.call( drag.dragging, event ); // trigger "drag"
					if ( $.event.special.drop ){ // manage drop events
						$.event.special.drop.allowed = ( returnValue !== false ); // prevent drop
						$.event.special.drop.handler( event ); // "dropstart", "dropend"
						}
					if ( returnValue !== false ) break; // "drag" not rejected, stop		
					event.type = "mouseup"; // hijack event
					}
			// mouseup, stop dragging
			case 'mouseup': // DRAGEND >> 
				$.event.remove( document.body, "mousemove mouseup", drag.handler ); // remove page events
				if ( drag.dragging ){
					if ( $.event.special.drop ) // manage drop events
						$.event.special.drop.handler( event ); // "drop"
					event.type = "dragend"; // hijack event
					$.event.handle.call( drag.dragging, event ); // trigger "dragend"	
					selectable( drag.dragging, true ); // enable text selection
					drag.dragging = drag.proxy = null; // deactivate element
					event.data = {};
					}
				break;
			} 
		} 
	};
	
// toggles text selection attributes	
function selectable( elem, bool ){ 
	if ( !elem ) return; // maybe element was removed ? 
	elem.unselectable = bool ? "off" : "on"; // IE
	elem.onselectstart = function(){ return bool; }; // IE
	if ( elem.style ) elem.style.MozUserSelect = bool ? "" : "none"; // FF
	};	
	
/*******************************************************************************************/
})( jQuery ); // confine scope













//apa első plugingja. 
(function($){
	$.fn.customScroll=function(dT,sT) {
        //kell nékünk 2div;
		  //
   var $this=$(this);
	return this.each(function(){
	var $thisWidth=parseInt($(this).width());
	var $thisHeight=parseInt($(this).height());
	var $thisOuterH=parseInt($(this).outerHeight());
	var parentDiv=$(this).parent('div');
	var $parentHeight=parseInt($(parentDiv).height());
	var parentOffset=$(parentDiv).offset();
	var parentId=$(parentDiv).attr("id");
	$("img#toltes").remove();
	//alert(' h '+$thisHeight+' ih '+$thisOuterH+' oh '+$thisOuterH+' ph '+$parentHeight);
	if ($thisOuterH<$parentHeight) {
		$(parentDiv).find("div.scrollbar").remove();
		return this;
	}
	if ($thisOuterH>$parentHeight)
	{
    if (dT && sT) {
        dTop=dT;
        sTop=sT;
    } else {
        dTop=0;
        sTop=0;
    }
	$(parentDiv).find("div.scrollbar, div.scrollpici").remove();
	//console.log('w'+$thisWidth+'h '+$thisHeight+'iw '+$thisInnerW+'ih '+$thisOuterH);
	parentDiv.css({position:"relative",overflow:"hidden"});
	$(this).css({position:"absolute", top:dTop,left:0,marginRight:14});
	var scrollH=Math.round($parentHeight-((($thisOuterH/$parentHeight)-1)*$parentHeight));
	if (parseInt(scrollH)<20) {
		scrollH=20;
	}
	$('<div class="scrollbar"></div>').css({position:"absolute",height:$parentHeight,width:"14px",backgroundColor:"#835138",top:0,right:0}).appendTo(parentDiv);
	$('<div class="scrollpici"></div>').css({position:"absolute",top:sTop,height:scrollH,width:"12px",border:"1px solid black",backgroundColor:"#fbeece",cursor:"pointer"})
	.bind('drag',function(event){
		curTop=event.offsetY-parentOffset.top;
		if (curTop>-1 && curTop+scrollH<$parentHeight) {
		var topPercent=curTop/$parentHeight;
		var thisTop=Math.round($thisOuterH * topPercent);
		$(this).css({top:curTop});
		$($this).css({top:0-(thisTop)});
		//console.log($parentHeight);
		}
		})
	.appendTo('div#'+parentId+' div.scrollbar');	
	}	
	});
	};

	
})(jQuery);


function backGround(elem,kep) {
	$(elem).css({background:'transparent url("'+kep+'") no-repeat left top'});
}
var linkTomb=[];
var linkIndex=0;
var that='';
var thisid='';
$(document).ready( function() {
	//globals

$("ol#menusor a").click(function(){
	$("h4#fejlec").text($(this).text());
	$('<img  id="toltes" src="termek_felvitele/css/wait.gif" alt="Töltés, kérem várjon" />').css({height:"19px"}).prependTo($("h4#fejlec"));
	var id=$(this).attr("id");
	if (id) {
		if (id.indexOf("stat")>-1)
		{

		switch (id) {
		case "stat_1":
		backGround("div#fejl8","kepek/focimkepek/nyito-08.jpg");
		backGround("div#fejl9","kepek/focimkepek/nyito-09.jpg");
		backGround("div#promo1","kepek/focimkepek/nyito-19b.jpg");
		backGround("div#promo3","kepek/focimkepek/nyito-24b.jpg");
		$("#navigacios_div").hide("slow");
		break;
		case "stat_5":
		backGround("div#fejl8","kepek/focimkepek/kisker08.jpg");
		backGround("div#fejl9","kepek/focimkepek/kisker09.jpg");
		backGround("div#promo1","kepek/focimkepek/sajtok19.jpg");
		backGround("div#promo3","kepek/focimkepek/boltok-24.jpg");
		$("#navigacios_div").hide("slow");
		break;
		case "stat_6":
		backGround("div#fejl8","kepek/focimkepek/nagyker08.jpg");
		backGround("div#fejl9","kepek/focimkepek/nagyker09.jpg");
		backGround("div#promo1","kepek/focimkepek/sajtok19.jpg");
		backGround("div#promo3","kepek/focimkepek/boltok-24.jpg");
		$("#navigacios_div").hide("slow");
		break;
		case "stat_7":
		backGround("div#fejl8","kepek/focimkepek/hirek08.jpg");
		backGround("div#fejl9","kepek/focimkepek/hirek09.jpg");
		backGround("div#promo1","kepek/focimkepek/sajtok19.jpg");
		backGround("div#promo3","kepek/focimkepek/boltok-24.jpg");
		$("#navigacios_div").hide("slow");
		break;
		case "stat_8":
		backGround("div#fejl8","kepek/focimkepek/nyito-08.jpg");
		backGround("div#fejl9","kepek/focimkepek/nyito-09.jpg");
		backGround("div#promo1","kepek/focimkepek/nyito-19b.jpg");
		backGround("div#promo3","kepek/focimkepek/nyito-24b.jpg");
		$("h4#fejlec").text("Bemutatkozás");
		$("#navigacios_div").hide("slow");
		break;
		}
		$("div#content_inner").load('oldalak/oldalak.php?o='+id,function(){$('div#content_inner').customScroll();tb_init('a.thickbox');
		$("div#content_inner div#galeria h4").click(function(){$(this).next("p").toggle("slow",function(){$('div#content_inner').customScroll($('div#content_inner').css("top"),$('div#content div.scrollpici').css("top"));});});$("a#stat_10").click(function() {
	    $("div#content_inner").empty()
	    $("div#content_inner").load('oldalak/oldalak.php?o=stat_10',function(){tb_init('a.thickbox');
        });
        return false;
        });});
		} else  {

		thisid=id;
		var kategoria_e=thisid.substr(thisid.lastIndexOf("_")+1,thisid.length);
		if (!Number(kategoria_e)) {			
			if ($('ol#menusor #'+thisid+' + ol > li > a[id$=0]').length) {
			$("div#content_inner").empty().css({margin:0});
			//$("div#content div.scrollbar").remove()			
			var clones=$('ol#menusor #'+thisid+' + ol > li > a[id$=0]').addClass("katmenu").clone(true);
			clones.appendTo("div#content_inner").hide().slideDown('slow',function(){$('div#content_inner').customScroll();});
			}  else {
			
			
			$("#navigacios_div").show();
			$("#navigacios_menu a").hide();
			linkIndex=0;
			$("#navigacios_menu a#"+thisid).next('ol').find("a[id$=1]").show(function(){$("div#relative_nav_inner").customScroll();});
			$("#navigacios_menu a#"+thisid).next('ol').find("a[id$=1]").each(function(i){
				linkTomb[i]=$(this).attr("id");	
				});
			
			}	
		}
		}
	$("a.husmenu, a.katmenu").css({backgroundColor:"#fbeece",color:"black"});
	$(this).parent("li").siblings("li").find("a").css({backgroundColor:"#fbeece",color:"black"});
	$(this).css({backgroundColor:"#efc243",color:"#bf3f00"});
	} else {
	$("ol#menusor a, a.husmenu, a.katmenu").css({backgroundColor:"#fbeece",color:"black"});
	$(this).css({backgroundColor:"#efc243",color:"#bf3f00"});
	if ($(this).next("ol").is(":hidden")) {
		$("ol#menusor ol").hide("fast");
		$(this).next("ol").show("fast");
		}
	$(this).next("ol").find("a:first").click();
	}
});


	$("ul#abc a").click(function() {
		var betuk=$(this).attr("id");
		var index=0;
	        linkTomb=[];
		linkIndex=0;
		$("ol#navigacios_menu a[id$=1]").each(function(i) {
			var elsob=$(this).text();
			elsob=elsob.substr(0,1).toLowerCase();

			if (betuk.indexOf(elsob)>-1) {
				linkTomb[index]=$(this).attr("id");
				index++;	
						
			}
		
		});
		$("ol#navigacios_menu a").hide();
		//alert(linkTomb.length);
		if (linkTomb.length)
			$('ol#navigacios_menu a#'+thisid).next("ol").find('a#'+linkTomb.join(', a#')).show(function(){$("div#relative_nav_inner").customScroll();});
		else
			alert("nincs ilyen betű");
	});
	
	
	$('ol#navigacios_menu a').click(function(){
		var id=$(this).attr("id");
		$("h4#fejlec").text($(this).text());
		$("div#content_inner").empty();
		$("div#content_inner").load('oldalak/oldalak.php?o='+id, function(){$('div#content_inner').customScroll();});

	});
	$("div#fel_nyil a").click(function(){
		if (linkTomb.length>7 && linkIndex>0) {
			linkIndex=linkIndex-5;
			if (linkIndex<5) {
				linkIndex=0;
			}
			var linkToShow=linkTomb.slice(linkIndex,linkTomb.length);
			$("ol#navigacios_menu a").hide();
			$('ol#navigacios_menu a#'+thisid).next("ol").find('a#'+linkToShow.join(', a#')).show("");		
		}
		
		});
	$("div#le_nyil a").click(function(){
		if (linkTomb.length>7 && linkIndex<(linkTomb.length-5)) {
			linkIndex=linkIndex+5;
			var linkToShow=linkTomb.slice(linkIndex,linkTomb.length);
			$("ol#navigacios_menu a").hide();
			$('ol#navigacios_menu a#'+thisid).next("ol").find('a#'+linkToShow.join(', a#')).show("");		
		}
		});
	//init
	backGround("div#promo1","kepek/focimkepek/nyito-19b.jpg");
	backGround("div#promo3","kepek/focimkepek/nyito-24b.jpg");
	backGround("div#fejl8","kepek/focimkepek/nyito-08.jpg");
	backGround("div#fejl9","kepek/focimkepek/nyito-09.jpg");
	$("div#content_inner").load('oldalak/oldalak.php?o=stat_1',function(){
        $("a#stat_10").click(function() {
	    $("div#content_inner").empty()
	    $("div#content_inner").load('oldalak/oldalak.php?o=stat_10',function(){tb_init('a.thickbox');
        });
        return false;
        });
    });
	$("h4#fejlec").text("Bemutatkozás");
	$(document).bind('contextmenu',function(e) {
		return false;
	});

	//próba
	//$("#navigacios_menu").hide();

});
