function productionHomeGetViewTab(anchorDom)
{
	var projectThumbList=$('#project_thumb_list');
	var projectTableList=$('#project_table_list');

	if(!projectThumbList.size() || !projectTableList.size())
	{
		return;
	}

	if(projectThumbList.css('display') != 'none')
		return;

	var anchor=$(anchorDom);

	var newHref=anchor.attr('href');

	if(newHref.indexOf('?') != -1 )
		newHref += '&';
	else
		newHref += '?';

	newHref += 'view=1';

	anchor.attr('href', newHref);
}

function productionDetailsSetGalleryVideo(anchorDom)
{
	var anchor=$(anchorDom);

	$('#video_row li').removeClass('current');

	var anchorParent=anchor.parent();

	anchorParent.addClass('current');

	var videoId=anchorParent.attr('id');
	productionGallerySetNewLocation('video', videoId);

	if(typeof(flowplayer0) != 'undefined')
	{
		//	$f().show();
		$f().load();
	}

	$('#gallery_main_holder').hide();
	$('#video_main_holder').show();
	$('#thumb_row li').removeClass('current');

	productionDetailsCheckPreviousNextButtons();

	if(typeof(flowplayer0) != 'undefined')
	{
		$f().play( anchor.attr('href') ); /*.substr(1)*/
	}

	//alert(anchor.attr('href'));
}

//// gallery image

function productionDetailsSetGalleryImage(anchorDom)
{
	var anchor=$(anchorDom);
	var img=$('#gallery_main_holder img');

	if(!img.size())
		return;

	var anchorParent=anchor.parent();

	// ovo mi treba jer pod operom ne mogu samo mjenjati src! :(
	var newImgAlt=anchorParent.find('img').attr('alt');

	//$('#gallery_main_holder').html('<img src="'+anchor.attr('href')+'" width="'+imgWidth+'" height="'+imgHeight+'" alt="'+newImgAlt+'" />');
	$('#gallery_main_holder').html('<img src="'+anchor.attr('href')+'" alt="'+newImgAlt+'" />');

	// ovo ne radi pod operom!!!
	//img.attr('src', anchor.attr('href') ); /*.substr(1)*/

	$('#thumb_row li').removeClass('current');

	anchorParent.addClass('current');

	var imgId=anchorParent.attr('id');
	productionGallerySetNewLocation('image', imgId);

	if( typeof(flowplayer0) != 'undefined' )
	{
		$f().stop();
		$f().unload();
		//	$f().hide();
	}

	$('#video_main_holder').hide();
	$('#gallery_main_holder').show();
	$('#video_row li').removeClass('current');

	productionDetailsCheckPreviousNextButtons();
}

function productionGallerySetNewLocation(prefix, strId)
{
	strId=strId.substr(1); // dobijem samo id

	var href=document.location.href;

	// maknem stari # i ostatak
	var ix=href.indexOf('#');

	if(ix>0)
	{
		href=href.substring(0, ix);
	}

	if(strId.length > 0 && prefix.length>0)
		document.location.href = href + '#' + prefix + '_' + strId;
}


function productionDetailsPreviousGalleryItem(anchorDom)
{
	var gtype=productionGalleryType();

	if(gtype=='image')
		var current=$('#thumb_row li.current');
	else if(gtype=='video')
		var current=$('#video_row li.current');
	else
		return;

	if(!current.size())
		return;

	var previous=current.prev();

	if(!previous.size())
		return;

	var previousA=previous.find('a');

	if(!previousA.size())
		return;

	if(gtype=='image')
		productionDetailsSetGalleryImage( previousA.get(0) );
	else if(gtype=='video')
		productionDetailsSetGalleryVideo( previousA.get(0) );
}


function productionDetailsNextGalleryItem(anchorDom)
{
	var gtype=productionGalleryType();

	if(gtype=='image')
		var current=$('#thumb_row li.current');
	else if(gtype=='video')
		var current=$('#video_row li.current');
	else
		return;

	if(!current.size())
		return;

	var next=current.next();

	if(!next.size())
		return;

	var nextA=next.find('a');

	if(!nextA.size())
		return;

	if(gtype=='image')
		productionDetailsSetGalleryImage( nextA.get(0) );
	else if(gtype=='video')
		productionDetailsSetGalleryVideo( nextA.get(0) );
}

function productionDetailsCheckPreviousNextButtons()
{
	var gtype=productionGalleryType();

	if(gtype=='image')
		var current=$('#thumb_row li.current');
	else if(gtype=='video')
		var current=$('#video_row li.current');
	else
		return;



	var back_link=$('#back_link');
	var back_text=$('#back_text');
	var next_link=$('#next_link');
	var next_text=$('#next_text');


if(!current.size())
{
		back_link.hide();
		back_text.show();
		next_link.hide();
		next_text.show();
		return;
}


if(!back_link.size())
		return;

if(!back_text.size())
		return;

if(!next_link.size())
		return;

if(!next_text.size())
		return;

/*
	if(!current.size() || !back_link.size() || !back_text.size() || !next_link.size() || !next_text.size())
		return;
*/
	if( current.prev().size())
	{
		back_link.show();
		back_text.hide();
	}
	else
	{
		back_link.hide();
		back_text.show();
	}

	if( current.next().size())
	{
		next_link.show();
		next_text.hide();
	}
	else
	{
		next_link.hide();
		next_text.show();
	}




}

function productionGalleryType()
{
	var vHolder=$('#video_main_holder');
	var iHolder=$('#gallery_main_holder');

	if(iHolder.size() && iHolder.css('display') != 'none' )
		return 'image';
	else if(vHolder.size() && vHolder.css('display') != 'none' )
		return 'video';

	return '';
}


function productionSetCurrentItem()
{
	var gtype=productionGalleryType();

	if(gtype=='image')
		var current=$('#thumb_row li.current');
	else if(gtype=='video')
		var current=$('#video_row li.current');
	else
		return;

	var back_link=$('#back_link');
	var back_text=$('#back_text');
	var next_link=$('#next_link');
	var next_text=$('#next_text');

	if(!current.size() || !back_link.size() || !back_text.size() || !next_link.size() || !next_text.size())
		return false;

	var href=document.location.href;

	var ix=href.indexOf('#');
	if(ix <=0 )
		return false;

	var strId=href.substr(ix+1);

	var ix=strId.indexOf('_');
	if( ix<=0)
		return false;

	var type=strId.substr(0, ix);

	if(type != 'image' && type != 'video')
		return;

	gtype=type;

	strId=parseInt(strId.substr(ix+1));

	if(strId<=0)
		return false;

	if(gtype=='image')
		var aObj=$('#thumb_row li#i' + strId + ' a');
	else if(gtype=='video')
		var aObj=$('#video_row li#v' + strId + ' a');


	if(!aObj.size())
		return false;


	if(gtype=='image')
	{
		productionDetailsSetGalleryImage( aObj.get(0) );

		/*$('#gallery_main_holder').show();
		$('#video_main_holder').hide();
		$('#video_row li').removeClass('current');*/
	}
	else if(gtype=='video')
	{
		productionDetailsSetGalleryVideo( aObj.get(0) );

		/*$('#gallery_main_holder').hide();
		$('#thumb_row li').removeClass('current');
		$('#video_main_holder').show();*/
	}

	return true;
}


var helpPdfTimeout=0;


$(document).ready(function() {

	$('a.ext').attr('target', '_blank');

	//hover help pdf
	$('a#pdf').hover(

			function()
			{
				clearTimeout(helpPdfTimeout);
				$('div.help_pdf').addClass('show');
			},

			function()
			{
				clearTimeout(helpPdfTimeout);
				helpPdfTimeout=setTimeout( "$('div.help_pdf').removeClass('show');", 50);
			}
		);

	$('#help_pdf').hover(
								function()
								{
									clearTimeout(helpPdfTimeout);
								},

								function()
								{
									clearTimeout(helpPdfTimeout);
									helpPdfTimeout=setTimeout( "$('div.help_pdf').removeClass('show');", 50);
								}
						  );

//hover tabs
	$('.jquery_hover li').hover(function() {
	    $(this).addClass('over');
      }, function() {
        $(this).removeClass('over');
	});


//switch table and thumb view (projects/works)
	$('a#thumb_list').click(function()
	{
		$('a#thumb_list').addClass('current');
		$('a#table_list').removeClass('current');

		$('#project_table_list').fadeOut(function () {
			$('#project_thumb_list').fadeIn();
		});

		$('#btn_view_thumb').hide();
		$('#btn_view_list').show();

		return false;
	});

	$('a#table_list').click(function()
	{
		$('a#thumb_list').removeClass('current');
		$('a#table_list').addClass('current');

		$('#project_thumb_list').fadeOut(function(){
			$('#project_table_list').fadeIn();
		});

		$('#btn_view_list').hide();
		$('#btn_view_thumb').show();

		return false;
	});


//form focus and blur styles
	$('input.text').focus(function() {
		$(this).addClass('active');
	});
	$('input.text').blur(function() {
		$(this).removeClass('active');
	});

	$('textarea.textarea').focus(function() {
		$(this).addClass('active');
	});
	$('textarea.textarea').blur(function() {
		$(this).removeClass('active');
	});

	$('dd.submit input').hover(function() {
	    $(this).addClass('over');
      }, function() {
        $(this).removeClass('over');
	});

/*
	if(!productionSetCurrentItem())
	{
		productionDetailsCheckPreviousNextButtons();
	}
*/
	productionDetailsCheckPreviousNextButtons();
});