$(function(){
    $("#modal").overlay({
    top: 0,
    close: '#close-modal',
    mask: {

            // you might also consider a "transparent" color for the mask
            color: '#ccc',

            // load mask a little faster
            loadSpeed: 200,

            // very transparent
            opacity: 0.85,
	    
    },

    // disable this for modal dialog-type of overlays
    fixed: false,
    
    closeOnClick: true,
    
    left: 0


    });	
    
});  


/* Google Maps */
function infoWindowContent()
{
	newDiv = document.createElement("div");
	jQuery(newDiv).html(jQuery("#map-info-box").html());

	return newDiv;
}
function initializeMap()
{
	jQuery("#static-map").fadeOut(function(){
            jQuery("#dynamic-map").show();
        });
	
	var map = new GMap2(document.getElementById("dynamic-map"));
	var latlng = new GLatLng(59.439511, 24.756036);
	var marker = new GMarker(latlng)

	map.removeMapType(G_HYBRID_MAP);
	map.removeMapType(G_SATELLITE_MAP);
	map.removeMapType(G_NORMAL_MAP);
	map.setCenter(latlng, 16);
	map.setUIToDefault();
	map.addOverlay(marker);
	
	GEvent.addListener(marker, "click", function() {
		map.openInfoWindowHtml(latlng, infoWindowContent());
	});

	map.openInfoWindowHtml(latlng, infoWindowContent());
}

/* Works, People, News */
function getWork( work_id )
{

	jQuery.ajax( {
		url: 'index.php?ajax=1&action=get_work&work_id=' + work_id,
		type: 'GET',
		success: function(html) {
			jQuery('#modal').html( html );
			showWork();
                        openMedia('video',$('.work-video').attr('href'));
                         openMedia('audio',$('.work-media').attr('href'));
		}
	});
}

function getPeople( people_id )
{
	jQuery.ajax( {
		url: 'index.php?ajax=1&action=get_people&people_id=' + people_id,
		type: 'GET',
		success: function(html) {
			jQuery('#modal').html( html );
			showWork();
		}
	});
}

function getNews( news_id )
{
	jQuery.ajax( {
		url: 'index.php?ajax=1&action=get_news&news_id=' + news_id,
		type: 'GET',
		success: function(html) {
			jQuery('#modal').html( html );
			showWork();
			//initWorkLinks();
		}
	});
}

function showWork()
{
        $("#modal").overlay().load();   
        $('#modal-slider').cycle({
            fx: 'fade',
            next: '.down',
            prev: '.up',
            timeout: 0,            
            pager: '#modal-slider-thumbs',
            pagerAnchorBuilder: function(idx, slide) { 
                    s = $('#'+slide.id).attr('data-tn');
                    return '<li><img src="'+s+'" alt="" /><div class="active"></div></li>'; 
            } 		            
        });
}

function hideWork()
{
    $("#modal").overlay().close();    
//	jQuery('#overlay').hide();
//	jQuery('#single-work').hide();
//	jQuery('#media-wraper').hide();
//	jQuery(window).scrollTop(window_scroll);
//	try {flowplayer().stop();flowplayer().unload();} catch(e) {};
}


function openMedia(type, media_url)
{

	try {flowplayer().stop();flowplayer().unload();} catch(e) {};

	if ( type == 'video')
	{
		flowplayer( 'workmedia', '/wp-content/themes/zavod/js/flowplayer/flowplayer-3.2.7.swf', {
			clip : {
				scaling: 'fit',
				autoPlay: true,
				autoBuffering: true,
				url: media_url
			} 
		} );
	}
	else if ( type == 'audio' )
	{
		flowplayer( 'work-media', '/wp-content/themes/zavod/js/flowplayer/flowplayer-3.2.7.swf', {
			clip : {
				autoPlay: true,
				autoBuffering: true,
				url: media_url
			},
			plugins: {
				audio: {url: '/wp-content/themes/zavod/js/flowplayer/flowplayer.audio-3.2.2.swf'},
				controls: {
					autoHide: false
				}
			}
		} );
	}

}
