// drop down menu

function P7_ExpMenu(){ //v1.1.0.2 by PVII-www.projectseven.com
 if(navigator.appVersion.indexOf("MSIE")==-1){return;}
 var i,k,g,lg,r=/\s*p7hvr/,nn='',c,cs='p7hvr',bv='p7menubar';
 for(i=0;i<10;i++){g=document.getElementById(bv+nn);if(g){
 lg=g.getElementsByTagName("LI");if(lg){for(k=0;k<lg.length;k++){
 lg[k].onmouseover=function(){c=this.className;cl=(c)?c+' '+cs:cs;
 this.className=cl;};lg[k].onmouseout=function(){c=this.className;
 this.className=(c)?c.replace(r,''):'';};}}}nn=i+1;}
}

function init_dropdown_menu () {
	P7_ExpMenu();

	$('#contakt_link_form').click(
		function()
		{
			$("#contakt_form").submit();
		}
	);
	$('#contakt_clean_form').click(
		function()
		{
			$("#names").val("");
			$("#phones").val("");
			$("#e_mail").val("");
			$("#request").val("");
		}
	);
	$("#names").focus(
		function()
		{
			//$("#names").val("");
		}
	);
	$("#phones").focus(
		function()
		{
			//$("#phones").val("");
		}
	);
	$("#e_mail").focus(
		function()
		{
			//$("#e_mail").val("");
		}
	);
	$("#request").focus(
		function()
		{
			//$("#request").val("");
		}
	);
	$(".items div img").click(
		function()
		{
			$('#album_title').text($(this).attr("alt"));
		}
	);

	$("li#hover_li").hover(
		function()
		{
			$('li#hover_li ul').css({'display' : 'block'});
		},
		function()
		{
			$('li#hover_li ul').css({'display' : 'none'});
		}
	);
	$("li#hover_li_1").hover(
		function()
		{
			$('li#hover_li_1 ul').css({'display' : 'block'});
		}
	);
	$("li.hover_li_class_1").hover(
		function()
		{
			$('li.hover_li_class_1 ul').css({'display' : 'block'});
		},
		function()
		{
			$('li.hover_li_class_1 ul').css({'display' : 'none'});
		}
	);
	$("a#show_form_div").click(
		function()
		{
			$('div#bestprice').css({'display' : 'block'});
		}
	);
	$("a#close_div").click(
		function()
		{
			$('div#bestprice').css({'display' : 'none'});
		}
	);

}

var slideshow_timer = null;

function control_slideshow(start) {
    var api = $("div.gallery_h_scrollable").scrollable();
    if (start && slideshow_timer == null) {
        // start show
        api.getConf().loop = true;
        api.getConf().size = 1;
        api.getConf().onSeek = function() {
            var big_img = api.getItems().children("a.id_container:eq(" + api.getIndex() +  ")").attr("href");
            $('img#central_image').fadeTo(500, 0.1);
            setTimeout(function() { $('img#central_image').attr('src', big_img) }, 500);
            $('img#central_image').fadeTo(500, 1);
        }
        api.reload();

		function setTimer() {
		    if (slideshow_timer == null) {
			    slideshow_timer = setInterval(function()  {
				    api.next();
			    } , 5000);
		    }
		}

		api.getRoot().hover(function() {
			clearInterval(slideshow_timer); slideshow_timer = null;
		}, function() {
			setTimer();
		});
		setTimer();

    } else {
        // stop show
		clearInterval(slideshow_timer);
        api.getConf().loop = false;
        api.getConf().size = 2;
        api.getConf().onSeek = function() {};
		api.getRoot().hover(function() {}, function() {});
        api.reload();
        slideshow_timer = null;
    }
}

function init_page_gallery() {
    init_dropdown_menu();

    // initialize scrollable
        $("div.gallery_v_scrollable").scrollable({
            next: 'div.s_down_arrow',
            prev: 'div.s_up_arrow',
            vertical:true,
            size: 3
        });

    $("div.gallery_v_scrollable div.items div").click(function() {
        //control_slideshow(false);
        current_slide = 0;
        $('a#current_slide').attr('href', '0');
        selected_album_id = $(this).children("a").attr("href");
        var album_data = albums[selected_album_id];

        $('img#central_image').attr('src', album_data['pics'][0]['medium_center']);
        $('a#central_img_slide').attr('href', album_data['pics'][0]['medium']);
        //$('a#central_img_slide').click(function(){return expand_slide_no(current_slide)});
        $('h3#album_title').html(album_data['title']);
/*
        var api = $("div.gallery_h_scrollable").scrollable();
        api.end(1);
        var countOld = api.getItems().length;
        for (i=0; i<countOld; i++) {
            api.getItems().filter(":last").remove();
        }
        api.reload();
*/
        $('iframe#iframe_scroller').attr('src', '/iframe_scroller.php?album=' + selected_album_id + '&page=1' + '&category=' + category);        

        var slideshow_sources = $("div#slideshow_sources")
        slideshow_sources.empty();
        //alert(album_data['pics_cnt']);
        for (i=0; i<album_data['pics_cnt']; i++) {
            /*            
            var new_img = '<img src="' + album_data['pics'][i]['small']
                + '"alt="' + album_data['title'] + '" title="' + album_data['title']
                + '" />  <a rel="nofollow" class="id_container" href="' + album_data['pics'][i]['medium']
                + '"></a><a rel="nofollow" class="id_slide" href="' + i + '"></a>';
            api.getItemWrap().append('<div>' + new_img + '</div>'); */

            /*if (i > 0) */{
                // first image is already loaded in the main image box
                var new_slide = '<a href="' + album_data['pics'][i]['medium']
                    + '" class="highslide" id="slide-no-' + i
                    + '" onclick="return hs.expand(this, {slideshowGroup: \'group1\'})"></a>';
                //slideshow_sources.html(slideshow_sources.html() + new_slide);
                slideshow_sources.append(new_slide);
            }
            //alert(album_data['pics'][i]['small']);
        }

        $("div.gallery_h_scrollable div.items div").click(function() {
            //control_slideshow(false);
            var big_img = $(this).children("a.id_container").attr("href");
            $('img#central_image').fadeTo(500, 0.1);
            setTimeout(function() { $('img#central_image').attr('src', big_img) }, 500);
            $('img#central_image').fadeTo(500, 1);
            current_slide = $(this).children("a.id_slide").attr("href");
        });

        //api.reload();
        //api.begin(1000);
    });

    $("div.gallery_h_scrollable").scrollable({
        next: 'div.s_right_arrow',
        prev: 'div.s_left_arrow',
        //interval: 2000,
        size: 2
    });

    $("div.gallery_h_scrollable div.items div").click(function() {
        var big_img = $(this).children("a.id_container").attr("href");
        $('img#central_image').fadeTo(500, 0.1);
        setTimeout(function() { $('img#central_image').attr('src', big_img) }, 500);
        $('img#central_image').fadeTo(500, 1);
        current_slide = $(this).children("a.id_slide").attr("href");
    });

}


function init_page_video() {
    init_dropdown_menu();

    // initialize scrollable
    $("div.gallery_v_scrollable").scrollable({
        next: 'div.s_down_arrow',
        prev: 'div.s_up_arrow',
        vertical:true,
        size: 3
    });


	// setup player
	$f("player", "/flowplayer-3.1.0.swf", {
	    autoPlay: false,
        autoBuffering: true,
	    baseUrl: 'http://duksfoto.com/files/videos/',

	    clip: {
    	    autoPlay: false,
    	    baseUrl: 'http://duksfoto.com/files/videos/',
            url: first_video
        }
    }
	).playlist("div.items", {playOnClick:false});

	$f("player").onLoad = (function () { this.pause(); });

	$f("player").load();


}


function init_page_full_left_scroll() {
    init_dropdown_menu();
    initializePage1();

}


function init_page_half_left_scroll() {
    init_dropdown_menu();
    initializePage();
}
