$(document).ready(function() {
    $("a.fancy").fancybox({
        'padding'               : 10,
        'overlayOpacity'        : 0.5,
        'overlayColor'          : '#000',
        'titlePosition'         : 'outside',
        'onStart'               : stopAnim,
        'onClosed'              : startAnim
    });
    $("a.gmap").fancybox({
        'padding'               : 10,
        'overlayOpacity'        : 0.5,
        'overlayColor'          : '#000',
        'titleShow'             : false,
        'titlePosition'         : 'outside',
        'onStart'               : stopAnim,
        'onClosed'              : startAnim
    });

    //printpage
    $("#printthis").click(function() {
        $("#printpage").printElement({ leaveOpen: true, printMode: 'popup', media:'print', overrideElementCSS: ['/css/styles_print.css'] });
    });

    //checkbox & radio
    $("input:radio").each( function() {
        (this.checked) ? $("#fake"+this.id).addClass('fakechecked') : $("#fake"+this.id).removeClass('fakechecked');
    });
    $(".fakeradio").click(function(){
        $("a.fakeradio").each( function() {
            $("a.fakeradio").removeClass('fakechecked');
        });
        ($(this).hasClass('fakechecked')) ? $(this).removeClass('fakechecked') : $(this).addClass('fakechecked');
        $(this.hash).trigger("click");
        return false;
    });
    $("input:checkbox").each( function() {
        (this.checked) ? $("#fake"+this.id).addClass('fakechecked') : $("#fake"+this.id).removeClass('fakechecked');
    });
    $(".fakecheck").click(function(){
        ($(this).hasClass('fakechecked')) ? $(this).removeClass('fakechecked') : $(this).addClass('fakechecked');
        $(this.hash).trigger("click");
        return false;
    });

    //footer link
    $("div#footer a.menu").hover( function () { $('div#footer a.menu').addClass("nocurrent"); }, function () { $('div#footer a.menu').removeClass("nocurrent"); });

    //ships quickinfo
    $("div#ship-1-menu, div#ship-2-menu, div#ship-3-menu, div#ship-4-menu, div#ship-5-menu").hide();
    $('div#header a.menu').not('#ship-fake').click(function() {
        $('div#ships div.fleft').hide();
        $('div#header a.menu').removeClass('current');
        $(this).addClass('current');
        $('#'+$(this).attr("id")+'-menu').show();
		setMenu($(this).attr("id"));
        return false;
    });
    $('#ship-5-secondlink').click(function() {
        $('div#ships div.fleft').hide();
        $('div#header a.menu').removeClass('current');
        $('div#header a#ship-5').addClass('current');
        $('#ship-5-menu').show();
		setMenu($(this).attr("id"));
        return false;
    });
    $("div#ships a").hover(
        function () {
            $('#'+$(this).attr("id")+'-info').show();
        },
        function () {
            $('#'+$(this).attr("id")+'-info').hide();
        }
    );

    //make your ship form
    $('#sendoffer').click(function() {
        $('#sendoffer-form').show('normal');
        return false;
    });

    //play & pause
    $('#pauseplay').click(function() {
        if ( $('#pauseplay img').attr('src') == '/gfx/navigation-play.png' ) {
            $('#pauseplay img').attr('src', '/gfx/navigation-pause.png');
            $('#pauseplay img').attr('alt', 'Folyamatos léptetés megállítása');
            $('#pauseplay img').attr('title', 'Folyamatos léptetés megállítása');
        } else {
            $('#pauseplay img').attr('src', '/gfx/navigation-play.png');
            $('#pauseplay img').attr('alt', 'Folyamatos léptetés indítása');
            $('#pauseplay img').attr('title', 'Folyamatos léptetés indítása');
        }
    });

    $('#clientgate').tooltip({title:'Az ügyfélkapu átmenetileg nem elérhető!'});

    $('#close-content').click(function() {
		 $('#content-inside').hide();
		 $('#open-content').show();
		 return false;
	});
    $('#open-content').click(function() {
		 $('#open-content').hide();
		 $('#content-inside').show();
		 return false;
	});

    //home
    $('a.morepages').click(function() {
        $('div.'+$(this).attr('rel')+' a.morepages').removeClass('current');
        $(this).addClass('current');
        $('div.'+$(this).attr('rel')+'-content').hide();
        $('div#home-'+$(this).attr('id')).show();
        return false;
    });

    //footer submenu
    $("div#footer a.menu").hover(
        function () {
            $('.submenu').hide();
            $('#sub'+$(this).attr("id")).show();
        }
    );
    $("img.activeslide, #container, #content-data, .contact, .privacy").hover(function () { $('.submenu').hide(); });

	if ($.cookie('animation') == 'stop') {
		setTimeout("stopAnim()", 1000);
	}

});

//cufon
Cufon.replace('#ships a',{hover:{color: '#fff'}});

//utvonal
function goToRoute(from, dst) {
	from = escape(from);

	if (dst == 1) {
		dst = escape("1138 Budapest, Váci út 113")+'+Magyarorsz%E1g';
	} else if (dst == 2) {
		dst = escape("8638 Balatonlelle, Köztársaság utca 36-38.")+'+Magyarorsz%E1g';
	} else {
		dst = '8638 Balatonlelle, Iparos u. 1.@N46.77111 E17.71929'; //escape("8638 Balatonlelle, Iparos u. 1.");
	}

	url = 'http://maps.google.com/maps?address='+from+'&country=Magyarorsz%E1g&saddr='+from+'+Magyarorsz%E1g&daddr='+dst;
	window.open(url,'blank');
}

/*
function toggle() {
    var times = 0;
    $('#header').animate({
        top: '-=100'
    }, times, function() {});
    $('#footer').animate({
        bottom: '-=50'
    }, times, function() {});
    $('#header, #footer').hover(
      function () {
        $('#header').animate({
            top: '+=100'
        }, times, function() {});
        $('#footer').animate({
            bottom: '+=50'
        }, times, function() {});
      },
      function () {
        $('#header').animate({
            top: '-=100'
        }, times, function() {});
        $('#footer').animate({
            bottom: '-=50'
        }, times, function() {});
      }
    );
}
*/


function storePush(ship, cat) {
    $.ajax({
        type: 'POST',
        data: $('input').serialize()+'&type='+cat,
        url: '/shipstore/push/'+ship+'/',
        success: function(msg){
            $('#shipsum').html(msg);
        }
    });
    return false;
}
function setMenu(cat) {
	$.get('/setmenu/'+cat+'/');
    return false;
}
var fromvideo = false;
function startAnim() {
	if ($.cookie('animation') == 'stop') return;
	if ( $('#stop-play').attr('src') != '/gfx/navigation-pause.png' ){
		$('#pauseplay').trigger('click');
	}
}

function stopAnim() {
	if ( $('#stop-play').attr('src') == '/gfx/navigation-pause.png' ){
		fromvideo = true;
		$('#pauseplay').trigger('click');
	}
}


function thisMovie(movieName) {
	if (window[movieName] == 'undefined' || window[movieName] == null)
		return document[movieName];
	else
		return window[movieName];
}

function stopPicture() {
	if (!fromvideo)
		$.cookie("animation", 'stop');
	thisMovie("animation").stopPicture();
	fromvideo = false;
}
function nextPicture() {
	thisMovie("animation").nextPicture();
}
function prevPicture() {
	thisMovie("animation").prevPicture();
}
function startPicture() {
	$.cookie("animation", 'start');
	thisMovie("animation").startPicture();
}
function downloadPicture() {
	thisMovie("animation").downloadPicture();
}
function setPictureName(picname) {
	window.open("/kepletoltes"+picname,'blank');
	return false;
}

