﻿vc_user_view_id = null;
vc_user_view_duration = 0;
vc_video_bak = '';
vc_current_content_type = 'video';

function vc_showContent(_sType, _iId, _sLink, _sLinkText, _sAlt, _sFirstType){
	
	//hide all menu items
	jQuery('.videocontext .vc_vkladki').removeClass('selected');
	//activate selected menu item
	jQuery('#vc_vkladka_'+_sType).addClass('selected');
	//hide already shown content
	jQuery('.videocontext .vc_contents').hide();

	//saving current content html (only if it's video)
	if(vc_current_content_type == 'video' && (jQuery('#vc_content_'+vc_current_content_type).html() != null && jQuery('#vc_content_'+vc_current_content_type).html().replace(/\s/g,"") != "")){
		vc_video_bak = jQuery('#vc_content_'+vc_current_content_type).html();
		//alert(vc_video_bak);
		jQuery('#vc_content_'+vc_current_content_type).html('loaded');
	}
	
	//if the selected content is show first time
	if(jQuery('#vc_content_'+_sType).html() == null || jQuery('#vc_content_'+_sType).html().replace(/\s/g,"") == "")
	{
		//get the contents and put it into the container
		vc_ajax(vc_root_path+'/proxy.php?url='+vc_parent_site_path+'/vc/vc.php', 'action=show_content&encoding='+vc_encoding+'&site='+vc_site_id+'&type='+_sType+'&id='+_iId+'&link='+_sLink+'&link_text='+_sLinkText+'&alt='+_sAlt+'&first_type='+_sFirstType, '#vc_content_'+_sType);
	}else if(_sType == 'video'){
		//restoring video html that has been already loaded. For IE...
		jQuery('#vc_content_'+_sType).html(vc_video_bak);
	}
	//show the selected container
	jQuery('#vc_content_'+_sType).show();
	
	vc_current_content_type = _sType;
}

function vc_ajax(_url, _params, _containerToUpdate, _onComplete){
	jQuery.ajax({
	   type: "POST",
	   url: _url,
	   data: "" + _params,
	   success: function(data){
			if(_containerToUpdate)
				jQuery(_containerToUpdate).html(data);
	   		if(_onComplete)
	   			eval(_onComplete);
	   }
	});
}

function vc_update_duration(){
	vc_ajax(
			vc_root_path+'/proxy.php?url='+vc_parent_site_path+'/vc/vc_update_user_view_duration.php', 'user_view_id=' + vc_user_view_id + '&duration=' + vc_user_view_duration
		);	
}

function vc_hide(){
	jQuery('.videocontext').hide();
}

function vc_show(){
	jQuery('.videocontext').hide();
}

function init_vc() {
	jQuery("a.vc_word").hover(
		//link hovered
		function(e){
			id = jQuery(this).attr("id");
			offset = jQuery(this).offset();
			offsetX = offset.left;
			offsetY = offset.top;
			//showAjaxLoader();
			vc_ajax(vc_root_path+'/proxy.php?url='+vc_parent_site_path+'/vc/vc.php', 'action=show&encoding='+vc_encoding+'&site='+vc_site_id+'&contents='+jQuery(this).attr("rel"), '#vc_main', 'show_window()');
			close1 = 0;
		},
		function(){
		}
	);
	//window
	jQuery(".videocontext").hover(
		//window hovered
		function(){
			jQuery(function(){
/*				jQuery(".videocontext ul li").each(function(){
					var temp = jQuery(".videocontext #adv_video").html();
					jQuery(this).click(function(){
						if(jQuery(".videocontext #adv_video")){
							if(this.id != "adv_video_link"){
								jQuery(".videocontext #adv_video").html("");
							}
							else{
								jQuery(".videocontext #adv_video").html(temp);
							}
						}
					});
				});*/
			});
		},
		//gone off the window
		function(){
			close1 = 1;
			window.setTimeout("window_out()", 500);
			//jQuery(".videocontext").html("");
		}
	);
	
	
}

function show_window(){
	
	if(window.pageYOffset) { var pageOffsetY = window.pageYOffset; }
	else if (document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop )) { var pageOffsetY = document.documentElement.scrollTop; }
	if(!pageOffsetY) pageOffsetY = 0;
	if(((document.getElementsByTagName('html')[0].clientHeight + pageOffsetY) - offsetY)<332) { offsetY = offsetY -332; };
	
	jQuery(".videocontext").css({top: offsetY-2, left: offsetX - 19});
	jQuery(".videocontext").show();
}

function hide_window(){
	jQuery(".videocontext").hide();
	jQuery(".videocontext").html("");
}

function window_out(){
	if(close1 == 0) 
		return false;
	hide_window();
	vc_update_duration();
}

function vc_increase_user_view_duration(){
	vc_user_view_duration += 1;
}

function vc_flush_user_view_duration(){
	vc_user_view_duration = 0;
	//alert(vc_user_view_duration);
}