/* Flash */
function InlineSWFObject(appURL,videoURL,imageURL,autostart)
{
	var rnd=parseInt(Math.random()* Math.pow(10,17));
	var s = new SWFObject(appURL + '/tools/player.swf?rnd='+rnd,'single','320','240','7');
	s.addVariable('file',videoURL);
	if(imageURL)
		s.addVariable('image',imageURL);
	s.addParam('autostart',autostart);
	s.addParam('allowfullscreen','true');
	s.addParam('wmode', 'transparent');

	/* X1 Banner parameters */
	/* always insert before 'plugins' variable */
	
	s.addVariable('x1adparams', escape("pub=803259725310407&site=provideo&section=homepage&zone=rectangle_video&size=0x0"));
	s.addVariable('x1pgid',		window.X1_PgId);
	s.addVariable('x1url',		escape(document.URL));
	s.addVariable('x1referrer',	escape(document.referrer));	
	s.addVariable('x1disabled',	'false');	
		
	s.addVariable("plugins",		"http://content.ad20.net/as3/plugins/jwplayer/X1Advertising.swf");
	
	document.write(s.getSWFHTML());
}
function getFlashMovie(movieName)
{
	  var isIE = navigator.appName.indexOf("Microsoft") != -1;
	  return (isIE) ? window[movieName] : document[movieName];
}

/* Wishlist */
var iCallId = 0;
var iPid = 0;
var sZone = "";
function WishlistView_Modify(act, id, zone)
{
	if(appLogged)
	{
		iCallId++;
		iPid = id;
		if(zone) sZone = zone;
		var HttpReq = new HttpAsyncPostRequest('wish_view_' + iCallId);
		HttpReq.Send(appURL + '/cart/modify_wish.aspx', {act: act, id: id}, WishlistView_Modify_Result);
	}
	else
	{
		PopUp_Open(appURL+'/tools/add_wishlist.aspx?u='+id,540,210);
	}
}

function WishlistView_Modify_Result(sResponse, sErrCode, sErrMessage)
{
	if(sResponse == "")
	{
		var o = document.getElementById('pw' + sZone + iPid);
		if(o) o.className += " wchecked";
	}
}

/* Videoteca */
function VideoView_Modify(act, id, zone)
{
	if(appLogged)
	{
		iCallId++;
		iPid = id;
		if(zone) sZone = zone;
		var HttpReq = new HttpAsyncPostRequest('video_view_' + iCallId);
		HttpReq.Send(appURL + '/cart/modify_video.aspx', {act: act, id: id}, VideoView_Modify_Result);
	}
	else
	{
	}
}

function VideoView_Modify_Result(sResponse, sErrCode, sErrMessage)
{
	if(sResponse == "")
	{
		var o = document.getElementById('pvv' + sZone + iPid);
		if(o) o.className += " wchecked";
	}
}


/* Element */

var iCallId=0;

function Element_GetXY(ObjRefOrId)
{
	var oR = {x:0, y:0};

	var o = typeof(ObjRefOrId) == 'string' ? document.getElementById(ObjRefOrId) : ObjRefOrId;
	if(!o) return oR;


	if(o.getBoundingClientRect)
	{
		var r = o.getBoundingClientRect(), 
			x = document.documentElement.scrollLeft || document.body.scrollLeft, 
			y = document.documentElement.scrollTop || document.body.scrollTop;
		oR = {x: r.left + x - 2, y: r.top + y - 2};
	}
	else
	{
		if(document.getBoxObjectFor)
		{
			var r = document.getBoxObjectFor(o);
			oR = {x: r.x, y: r.y};
		}
		else
		{
			var p = o.offsetParent;
			if (p != o)
			{
				while (p)
				{
					oR.x += p.offsetLeft;
					oR.y += p.offsetTop;
					p=p.offsetParent;
				}
			}
		}
	}

	return oR;
}



function Element_GetWidth(ObjRefOrId)
{
	var iW, o = typeof(ObjRefOrId) == 'string' ? document.getElementById(ObjRefOrId) : ObjRefOrId;
	if(!o) return 0;

	if(o.style.display == 'none')
	{
		o.style.display = '';
		iW = o.offsetWidth;
		o.style.display = 'none';
	}
	else
		iW = o.offsetWidth;

	return iW;
}



function Element_GetHeight(ObjRefOrId)
{
	var iH, o = typeof(ObjRefOrId) == 'string' ? document.getElementById(ObjRefOrId) : ObjRefOrId;
	if(!o) return 0;

	if(o.style.display == 'none')
	{
		o.style.display = '';
		iH = o.offsetHeight;
		o.style.display = 'none';
	}
	else
		iH = o.offsetHeight;

	return iH;
}



function Element_SetWidth(ObjRefOrId, Height)
{
	var iW, o = typeof(ObjRefOrId) == 'string' ? document.getElementById(ObjRefOrId) : ObjRefOrId;
	if(!o) return;
	
	o.style.width = parseInt(Height) + 'px';
}



function Element_SetDisplay(ObjRefOrId, Show)
{
	var o = typeof(ObjRefOrId) == 'string' ? document.getElementById(ObjRefOrId) : ObjRefOrId;
	if (o) 
		o.style.display = Show ? '' : 'none';
}

/* Box */

function Toggle_Visibility(id, img_id, imgPath) 
{  
	var o = document.getElementById(id);
	var list = o.getElementsByTagName("li");
	var bShow = false;
	var img = document.getElementById(img_id);

	for(i=1;i<list.length;i++) {
		if (list[i].style.display == "none")
		{
			bShow = true || bShow;
			list[i].style.display = "block";
		}
	}
	
	if (!bShow)
	{
		for(i=1;i<list.length;i++) {
			list[i].style.display = "none";
		}
		img.src = imgPath + "box_arrow_open.gif";
	} else
	{
		img.src = imgPath + "box_arrow_close.gif";
	}
} 

function Close_Visibility(id, img_id, imgPath) 
{ 

	var o = document.getElementById(id);
	var list = o.getElementsByTagName("li");
	var bShow = false;
	var img = document.getElementById(img_id);

	for(i=1;i<list.length;i++) {
		list[i].style.display = "none";
	}
	img.src = imgPath + "box_arrow_open.gif";
	
} 




/* Event */


function Event_AddListner(ObjRef, EvtName, FncRef)
{
	if(!ObjRef)return;
	if(window.attachEvent) ObjRef.attachEvent("on"+EvtName.toLowerCase(),FncRef);
	else if(window.addEventListener) ObjRef.addEventListener(EvtName.toLowerCase(),FncRef, false);
}


/* Menu */


var Menu_Obj = null;


function Menu_Show(MenuElementId, ClickedElementRef, CallbackFnc, CallbackFncParams)
{
	if(Menu_Obj)
	{
		Menu_Obj.MenuElementRef.style.display = 'none';

		if(Menu_Obj.ClickedElementRef == ClickedElementRef)
		{
			Menu_Obj = null;
			return;
		}
	}

	Menu_Obj =
	{
		ClickedElementRef:	ClickedElementRef,
		MenuElementId:		MenuElementId,
		CallbackFnc:		CallbackFnc,
		CallbackFncParams:	CallbackFncParams
	};

	var o = document.getElementById(MenuElementId);
	if(o)
	{
		Menu_Obj.MenuElementRef = o;

		var oXY = Element_GetXY(ClickedElementRef);

		o.style.display = '';
		o.style.left	= (oXY.x + Element_GetWidth(ClickedElementRef) - Element_GetWidth(o)) + 'px';
		o.style.top		= (oXY.y + Element_GetHeight(ClickedElementRef) + 10) + 'px';
		

		var f = typeof(CallbackFnc) == 'function' ? CallbackFnc : eval(CallbackFnc);

		if(typeof(f) == 'function')
		{
			f(CallbackFncParams);
		}
	}
}


function Menu_Hide(ev)
{
	if(Menu_Obj)
	{
		var t = (window.event ? window.event.srcElement : (ev ? ev.target : null));
		
		if (t == Menu_Obj.ClickedElementRef) return;

		if(Menu_Obj.MenuElementRef)
			Menu_Obj.MenuElementRef.style.display = 'none';

		Menu_Obj = null;
	}
}


function Menu_AddBodyClickHandler()
{
	Event_AddListner(window.document.body, 'click', Menu_Hide);
}


Event_AddListner(window, 'load', Menu_AddBodyClickHandler);





/* PopUp Window */


function PopUp_Open(URL, Width, Height)
{
	var w = screen.availWidth, h = screen.availHeight, l = 0, t = 0;
	
	l = Math.round((w-Width-10)/2);
	t = Math.round((h-Height-30)/2);

	window.open(URL,'PopUpWindow', "width="+Width+",height="+Height+",left="+l+",top="+t+",location=0,menubar=0,resizable=1,scrollbars=1,status=1,toolbar=0");
}





/* Cookies */


function Cookie_Get(sName)
{
	var i, v = document.cookie.split(';'), vT;
	
	for (i = 0; i < v.length; i++)
	{
		vT = v[i].split(sName + '=');	if (vT.length > 1) return vT[1];
	}

	return null;
}

function Cookie_Set(sName, sValue, iSeconds)
{
	var sE = "";

	if (iSeconds)
	{
		var d = new Date();
		d.setTime(d.getTime() + iSeconds * 1000);
		sE = '; expires=' + d.toGMTString();
	} 

	document.cookie = sName + '=' + sValue + sE + '; path=/';
}

function Cookie_Delete(sName)
{
	Cookie_Set(sName, '', -1);
}




/* String */

function String_Trim(s)
{
	return typeof(s) == 'undefined' ? '' : s.toString().replace(/^\s+|\s+$/g, '');
}


/* Email */

function CheckEmailAddress(field)
{
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	var goodEmail = filter.test(field);
	return goodEmail
}

/* Login */
//Event_AddListner(window, 'load', Login_Set);
function Login_Set()
{
	Attach_Focus('semail');
	Attach_Focus('spassword');
}
function Attach_Focus(objName)
{
	var o = document.getElementById(objName);
	if(o) 
	{
		Event_AddListner(o, 'focus', Input_Focus);
		Event_AddListner(o, 'blur', Input_Blur);
	}
}
function Input_Focus(ev)
{
	var o = (window.event ? window.event.srcElement : (ev ? ev.target : null));
	if(o) 
	{
		if(!document['store' + o.name] || document['store' + o.name] == o.value)
		{
			document['store' + o.name] = o.value;
			o.value='';
		}					
	}		
}
function Input_Blur(ev)
{
	var o = (window.event ? window.event.srcElement : (ev ? ev.target : null));
	if(o) 
	{
		if( document['store' + o.name] && o.value.length <= 0 )
		{
			o.value=document['store' + o.name];
		}
	}		
}


/* date validation */

var minYear = 1900;
function daysInFebruary (year){
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	var days = [];
	for (var i = 1; i <= n; i++) {
		days[i] = 31
		if (i == 4 || i == 6 || i == 9 || i == 11) { days[i] = 30 }
		if (i == 2) { days[i] = 29 }
	}
	return days
}



/* tooltip */
var offsetxpoint=-120 //Customize x offset of tooltip
var offsetypoint=20 //Customize y offset of tooltip
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["tooltip"] : document.getElementById? document.getElementById("tooltip") : ""


function ietruebody() {

	return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body

}

function ddrivetip(thediv, thetext, thecolor, thewidth) {
	tipobj = document.all ? document.all[thediv] : document.getElementById ? document.getElementById(thediv) : "";
	if (ns6 || ie) {
		if (typeof thewidth != "undefined") tipobj.style.width = thewidth + "px"
		if (typeof thecolor != "undefined" && thecolor != "") tipobj.style.backgroundColor = thecolor
		if (thetext)
			tipobj.innerHTML = thetext
		enabletip = true
		return false
	}
}
function positiontip(e) {
	if (!tipobj) return;
	if (enabletip) {
		var curX = (ns6) ? e.pageX : event.clientX + ietruebody().scrollLeft;
		var curY = (ns6) ? e.pageY : event.clientY + ietruebody().scrollTop;
		console.log(curX);
		//Find out how close the mouse is to the corner of the window
		var rightedge = ie && !window.opera ? ietruebody().clientWidth - event.clientX - offsetxpoint : window.innerWidth - e.clientX - offsetxpoint - 20
		var bottomedge = ie && !window.opera ? ietruebody().clientHeight - event.clientY - offsetypoint : window.innerHeight - e.clientY - offsetypoint - 20

		var leftedge = (offsetxpoint < 0) ? offsetxpoint * (-1) : -1000

		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge < tipobj.offsetWidth)
		//move the horizontal position of the menu to the left by it's width
			tipobj.style.left = ie ? ietruebody().scrollLeft + event.clientX - tipobj.offsetWidth + "px" : window.pageXOffset + e.clientX - tipobj.offsetWidth + "px"
		else if (curX < leftedge)
			tipobj.style.left = "5px"
		else
		//position the horizontal position of the menu where the mouse is positioned
			tipobj.style.left = curX + offsetxpoint + "px"

		//same concept with the vertical position
		if (bottomedge < tipobj.offsetHeight)
			tipobj.style.top = ie ? ietruebody().scrollTop + event.clientY - tipobj.offsetHeight - offsetypoint + "px" : window.pageYOffset + e.clientY - tipobj.offsetHeight - offsetypoint + "px"
		else
			tipobj.style.top = curY + offsetypoint + "px"
		tipobj.style.visibility = "visible"

	}
}
function hideddrivetip() {
	if (!tipobj) return;
	$(tipobj).css({ visibility: 'hidden' }); ;
}
document.onmousemove=positiontip






/* updated code */

$(function () {

	Attach_Focus('keywords');


	//filtreaza dupa
	$("div.filtre_inside div.filtreaza_dupa div.select a").click(function () {
		var sel = $(this).attr("link");
		$("div.dorpdown_filter").hide();
		$("div." + sel).toggle();
		return false;
	});

	//SetupCarousell();

	//body click
	$("body").click(function () {
		//hide dropdowns
		$("div.dorpdown_filter").hide();
	});
	//return;

	//tip
	$('.info').mousemove(function (e) {
		//console.log(e.pageX, e.pageY);
		var p1 = $('#comenzi1');
		var off = $(this).offset();
		var curX = e.pageX;
		var curY = e.pageY;
		p1.css({ left: curX - off.left - p1.width()/2, top: curY - off.top + 20 });

	}).mouseover(function (e) {
		var p1 = $('#comenzi1');
		p1.css({ visibility: "visible" });
	}).mouseout(function (e) {
		var p1 = $('#comenzi1');
		p1.css({ visibility: "hidden" });
	});

	//social share
	$('#social-share').dcSocialShare({
		location: 'top',
		align: 'left',
		tabText: '',
		offsetLocation: 310,
		offsetAlign: 30,
		width: 70,
		center: true,
		centerPx: 575,
		speedContent: 200,
		speedFloat: 1600,
		zIndex: 1,
		disableFloat: true,
		size: 'vertical',
		twitterId: 'ProVideoMag',
		buttons: 'facebook,twitter,plusone'
	});
});

function SetupCarousell() {
	//show only visible carousels
	$("div.scr_container:visible").jCarouselLite({
		circular: false,
		//mouseWheel: true,
		speed: 400,
		visible: 5,
		scroll: 4,
		btnNext: "a.arrow_right",
		btnPrev: "a.arrow_left"
	}).attr("carousel", "1");


	//setup tab clicks
	$("div.box_filme div.box_filme_top div.select_in ul li a").click(function () {
		$("a", $(this).parent().parent()).removeClass("selected");
		$(this).addClass("selected");
		var tab = "div." + $(this).attr("tab");
		var mainDiv = $(this).closest("div.box_filme");
		if ($(tab, mainDiv).length == 1) {
			$("div.scroller_filme", mainDiv).hide();
			$(tab, mainDiv).show();
			//enable carousell only if not allready
			if ($(tab + " div.scr_container", mainDiv).attr("carousel") != "1") {
				$(tab + " div.scr_container", mainDiv).jCarouselLite({
					circular: false,
					//mouseWheel: true,
					speed: 400,
					visible: 5,
					scroll: 4,
					btnNext: "a.arrow_right",
					btnPrev: "a.arrow_left"
				}).attr("carousel", "1");
			}
		}
	});
}
