var URL_BK = '';
function getURL(URL, jQueryPopupWidth, jQueryPopupHeight,endUrl){
	if(!URL) return;
	var fancy_id = arguments[4];
	var HTTP_HOST = 'http://' + window.location.hostname;
	
	//url
	var regExp = new RegExp(HTTP_HOST);
	
	if(regExp.test(URL)) {
		URL.replace(HTTP_HOST, '');
	}else {
		var regExp = new RegExp('http://');
		if(regExp.test(URL)) {
			URL = URL;
		}else {
			URL = HTTP_HOST.concat(URL);
		}
	}
	
	var extension = URL.substr(URL.lastIndexOf('.')+1, URL.length);
	var match = /(avi)|(swf)|(flv)|(mp4)|(wmv)|(mpeg)/.test(extension.toLowerCase());
	if(match) {
		videoclip = URL;
		if(extension=='avi') {
			movie =
				'<CENTER>'
				+ '<OBJECT ID="Video" width="305" height="250" classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"'
					+ 'type="application/x-oleobject" VIEWASTEXT>'
					+ '<PARAM NAME="FileName" VALUE="'+ videoclip +'">'
					+ '<PARAM NAME="ShowControls" VALUE="True">'
					+ '<PARAM NAME="ShowStatusBar" VALUE="True">'
					+ '<PARAM NAME="TransparentAtStart" Value="True">'
					+ '<PARAM NAME="AutoStart" Value="true">'
					+ '<PARAM NAME="AnimationatStart" Value="True">'
					+ '<PARAM NAME="autoSize" Value="false">'
					+ '<PARAM NAME="displaySize" Value="False">'
					+ '<PARAM NAME="enableContextMenu" Value="False">'
					+ '<PARAM NAME="uiMode" Value="invisible">'
					+ '<EMBED type="application/x-mplayer2"'
						+ 'pluginspage = "http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/"'
						+ 'SRC="'+ videoclip +'" Name="MediaPlayer1" Width="305" Height="250"'
						+ 'autoStart=1 transparentAtStart=1 animationAtStart=1 autoSize=0 ShowStatusBar=1 ShowControls=1'
						+ 'displaySize=0 enableContextMenu=0 uiMode="invisible" align="center">'
					+ '</EMBED>'
				+ '</OBJECT>'
				+'</CENTER>';
			$(".player").fancyboxOld({
				'autoRun':true,
				'hideOnContentClick':false,
				'overlayOpacity' :.6,
				'speedIn'    :400,
				'speedOut'   :400,
				'easingIn'		 : 'easeOutBack',
				'easingOut'		 : 'easeInBack',
				'callbackOnShow' :function(){
					$('#fancy_div').html(movie);
					$('#fancy_close').click(function(){
						$("#fancy_div_api").remove();
					});
				},
				'callbackOnClose':function(){
					if($.trim(endUrl)!="#"&& $.trim(endUrl)!=""){
						endUrl = endUrl.substr(1, endUrl.length);
						if(!document.location.href.match('[?]')){
							var go_to =document.location.href+'?'+endUrl;
						}else{
							var go_to =document.location.href.substr(0,document.location.href.lastIndexOf('?'))+'?'+endUrl;
						}
						window.location=go_to;
					}
				}
			});
			
			$('#player').click(function(){
				$(this).fancyboxOld({
					'autoRun':true,
					'hideOnContentClick':false,
					'overlayOpacity' :.6,
					'speedIn'    :400,
					'speedOut'   :400,
					'easingIn'		 : 'easeOutBack',
					'easingOut'		 : 'easeInBack',
					'callbackOnShow' :function(){
						$('#fancy_div').html(movie);
						$('#fancy_close').click(function(){
							$("#fancy_div_api").remove();
						});
					},
					'callbackOnClose':function(){
						if($.trim(endUrl)!="#"&& $.trim(endUrl)!=""){
							endUrl = endUrl.substr(1, endUrl.length);
							if(!document.location.href.match('[?]')){
								var go_to =document.location.href+'?'+endUrl;
							}else{
								var go_to =document.location.href.substr(0,document.location.href.lastIndexOf('?'))+'?'+endUrl;
							}
							window.location=go_to;
						}
					}
				});
			});
		}
		else if(extension=='swf') {
		    $.fancybox({
		        href: URL,
		        width: 300, height: 300,
		        scrolling: 'no',
		        autoDimensions: true,
		        'onComplete': function(){
		        	//
				},
				'onClosed':function(){
					if($.trim(endUrl)!="#"&& $.trim(endUrl)!=""){
						endUrl = endUrl.substr(1, endUrl.length);
						if(!document.location.href.match('[?]')){
							var go_to =document.location.href+'?'+endUrl;
						}else{
							var go_to =document.location.href.substr(0,document.location.href.lastIndexOf('?'))+'?'+endUrl;
						}
						window.location=go_to;
					}
				}
		    });
		}
		else if(extension=='flv'||extension=='mp4' || extension=='mpeg' || extension=='wmv') {
			
		    var container = $('<div id="video_container" style="width: 300px; height: 300px;"/>');
		    container.flowplayer(
		        swfplayer,
				{
					clip:{
						url: URL,
						//provider: 'lighttpd' ,
						onStart:function(clip){
							var clipwidth = clip.metaData.width;
							var clipheight= clip.metaData.height;
							$("#fancybox-wrap").css({width:clipwidth});
							$("#fancybox-content,#fancybox-content div").css({width:clipwidth,height:clipheight});
							$("#video_container_api").attr({'width': clipwidth+"px",'height': clipheight+"px"});
							$("#fancybox-outer").css({width:clipwidth+20,height:clipheight});
							$.fancybox.resize();
						},
						onFinish:function(){
							//$('#fancy_close').trigger('click');
							
						}
					}
				}
		    );
		    $.fancybox({
		        content: container,
		        width: 300, height: 300,
		        scrolling: 'no',
		        autoDimensions: true,
		        'onComplete': function(){
		        	//
				},
				'onClosed':function(){
					if($.trim(endUrl)!="#"&& $.trim(endUrl)!=""){
						endUrl = endUrl.substr(1, endUrl.length);
						if(!document.location.href.match('[?]')){
							var go_to =document.location.href+'?'+endUrl;
						}else{
							var go_to =document.location.href.substr(0,document.location.href.lastIndexOf('?'))+'?'+endUrl;
						}
						window.location=go_to;
					}
				}
		    });
			
		}
	}else {
		href = URL;
		$("a.iframe").topFancybox({
		    'hideOnContentClick': false,
		    'frameWidth': (jQueryPopupWidth?jQueryPopupWidth:800),
		    'frameHeight': (jQueryPopupHeight?jQueryPopupHeight:600),
		    'centerOnScroll': false,
		    'overlayShow': true,
		    //'overlayOpacity': .75,
		    'href': href,
		    'classiFrame': 'iframe'
		});
	}
}

(function($) {
   $.fn.topFancybox = function(settings) {
       // we would like to clone this node, but IE does not support importNode
       // instead, we will settle for creating a copy of this link in the parent document
       var a = top.document.createElement('a');
       a.style.display = 'none';
       //a.class = settings.classiFrame;
       a.setAttribute('class', settings.classiFrame);
       //a.href = settings.docURL;
       a.setAttribute('href', settings.href);
       top.document.body.appendChild(a);
       $(a).fancyboxOld(settings);
       $(a).click();
   };
})(jQuery);
function redirectPage(url,anchor){
	var form_hidden ='<form id="formHidden" action="'+url+'" method="post" style="display: none;">'+ 
					    '<input type="hidden" name="anchor" value="#'+anchor+'" />'+
					'</form>';
	$('body').append(form_hidden);
	$('#formHidden').submit();
}
/*(function($) {
   $.fn.topFancybox = function(settings) {
       // we would like to clone this node, but IE does not support importNode
       // instead, we will settle for creating a copy of this link in the parent document
       var a = top.document.createElement('a');
       a.style.display = 'none';
       a.class = this.class;
       a.href = this.href;
       top.document.body.appendChild(a);
       $(a).fancyboxOld(settings);
       $(a).click();
   };
})(jQuery);*/
