// Global Variables
var temp="", temp2="", temp3="";
var working=false;
var func;
var currHero = 0;
var countHeroes = 0;
var countSlides = 0;
var countSet	= 0;
var intervalID = 0;
var includePath = "/FoxCrime/includes/";
// Plugin: Slideshow
(function($) { // Compliant with jquery.noConflict()
	$.fn.foxSlide = function(o) {
		o = $.extend({
			btnPrev: ".slideprev",
			btnNext: ".slidenext",
			btnSetPrev: ".slidesetprev",
			btnSetNext: ".slidesetnext",
			slideContainer: ".slidecontainer",
			zoomtype: "change", // we may add lightbox-like plugin support
			change: ".mainphoto",
			slides: ".slides",
			slide: ".slide",
			photo: ".photo",
			vertical: false,
			circular: true,
			captions: false,
			customSlide: false,
			captionContainer: ".slidecaption",
			mouseWheel: false, // load mousewheel plugin to use this
			thumbs: true,
			auto: false,
			ajax: false,
			ajaxload: "onload", // or "onclick"
			speed: 800,
			easing: "linear", // load easing pluing for more options
			visible: 5,
			start: 0,
			scroll: 5,
			beforeStart: null,
			afterEnd: null
		}, o || {});
	
		return this.each(function() { 
			// Get Variables and Settings
			var running = false;
			var animCss=o.vertical?"top":"left", sizeCss=o.vertical?"height":"width";
			var domSlideShow = $(this);
			var domSlides = $(o.slides, domSlideShow);
			var domSlide = $(o.slide, domSlideShow);
			var domPhoto = $(o.photo, domSlideShow);
			var domChange = $(o.change, domSlideShow);
			var domContainer = $(o.slideContainer, domSlideShow);
			var indexCurrent = o.start;
			var indexSet = 0;
			countSlides = domSlide.size();
			//alert(countSlides);
			countSet = Math.ceil(countSlides/o.visible);
			var countVisibles = o.visible;
			// Calculations
			var dimensionSlide = o.vertical ? height(domSlide) : width(domSlide);
			//alert("domSlide"+domSlide[0].tagName);
			var dimensionSlides = dimensionSlide*countSlides;
			var dimensionVisible = dimensionSlide*countVisibles;
			var dimensionShift = 0;
			// Set Necessary Styles
			domSlides.css({margin: "0", padding: "0", position: "relative", "list-style-type": "none", "z-index": "1"});
			domSlide.css({overflow: "hidden", float: o.vertical ? "none" : "left"});
			domContainer.css({overflow: "hidden", position: "relative", "z-index": "2", left: "0px"});
			//alert("adet:"+countVisibles+"tanesi"+dimensionSlide+"toplam"+dimensionVisible+"asd");
			domContainer.css(sizeCss, dimensionVisible+"px");
			domSlides.css(sizeCss, dimensionSlides+"px").css(animCss, -(indexCurrent*dimensionSlide));
			domSlideShow.find(o.slide+":eq("+o.start+")").addClass("active");
			if(o.thumbs===true) {
				domSlideShow.find(o.slide+":eq("+o.start+")").find("a").append('<span class="activethumb"></span>');
			}
			// Ajax on Load
			if(o.ajax===true && o.ajaxload=="onload") {
				//alert("test");
			}
			// Effects
			$(o.btnNext, o.btnPrev, o.btnSetPrev, o.btnSetNext).hover(function() {
					$(this).addClass("hover");
				}, function() {
					$(this).removeClass("hover");
			});
			// Events
			if(o.zoomtype!="gotourl") {
				$(domSlide).find("a").click(function(e) {	
					e.preventDefault();
					temp = $(this);
					domSlides.find(".active").removeClass("active");
					domSlides.find(".activethumb").remove();
					temp.parent().addClass("active").find("a").append('<span class="activethumb"></span>');
					if(o.captions===true) { $(o.captionContainer).text(temp.find("img").attr("alt")); }
					if(o.zoomtype=="change") {
						temp2 = domSlide.index(temp.parent());
						indexCurrent = temp2;
						temp2 = $(this).attr("href");
						domChange.find("img").attr("src",temp2);
					}
				});
			}
			if(o.btnSetPrev) {
				$(o.btnSetPrev).click(function(e) {
					e.preventDefault();
					if(o.ajax===true && o.ajaxload=="onclick") {
						//alert("test");
					} else {
					slideTo(indexSet-1);
					}
				});
			}
			if(o.btnSetNext) {
				$(o.btnSetNext).click(function(e) {
					e.preventDefault();
					if(o.ajax===true && o.ajaxload=="onclick") {
						//alert("test");
					} else {
					slideTo(indexSet+1);
					}
				});
			}
			if(o.customSlide) {
				$(o.customSlide).click(function(e) {
					e.preventDefault();
					temp = $(this).attr("rel");
					//alert("test"+temp);
					//temp2 = domSlideShow.find(domSlide).index(domSlideShow.find("."+temp));
					temp2 = $("#fullschedule .program").index($("#fullschedule ."+temp));
					temp2 = Math.floor(parseInt(temp2, 10)/5);
					//alert("test"+temp2);
					slideTo(temp2);
				});
			}
			if(o.btnPrev) {
				$(o.btnPrev).click(function(e) {
					e.preventDefault();
					func="btnPrev";
					navigate(indexCurrent-1);
				});
			}
			if(o.btnNext) {
				$(o.btnNext).click(function(e) {
					e.preventDefault();
					func="btnNext";
					navigate(indexCurrent+1);
				});
			}
			if(o.mouseWheel && domSlideShow.mousewheel) { // Mousewheel support
				domSlideShow.mousewheel(function(e, d) {
					return d>0 ? slideTo(indexCurrent-o.scroll) : slideTo(indexCurrent+o.scroll);
				});
			}	
			if(o.auto!==false) {
				setInterval(function() { // Auto-slide with time
					func="btnNext";
					navigate(indexCurrent+1);
				}, o.auto+o.speed);
			}
			function vis() {
            	return domSlide.slice(indexCurrent).slice(0,countVisibles);
			}
			// Operations
	        function navigate(to) {
            	if(!running) {
					running = true;
					if(to<0) {
						indexCurrent = countSlides-1;
					} else if(to>countSlides-1) {
						indexCurrent = 0;
					} else {
						indexCurrent = to;
					}
					domSlides.find(".active").removeClass("active");
					domSlides.find(".activethumb").remove();
					temp = domSlideShow.find(o.slide+":eq("+indexCurrent+")");
					temp.addClass("active");
					if(o.thumbs===true) { temp.find("a").append('<span class="activethumb"></span>'); }
					if(o.captions===true) { $(o.captionContainer).text(temp.find("img").attr("alt")); }
					temp = temp.find("a").attr("href");
					domChange.find("img").attr("src",temp);
					if(func=="btnNext" && indexCurrent%o.visible===0) {
						running=false;
						slideTo(Math.floor(indexCurrent/o.visible));
					}
					if(func=="btnPrev" && (indexCurrent%o.visible==o.visible-1 || indexCurrent==countSlides-1)) {
						running=false;
						slideTo(Math.floor(indexCurrent/o.visible));
					}
					running = false;
					return false;
				}
			}
	        function slideTo(to) {
            	if(!running) {
					if(o.beforeStart) {
	                    o.beforeStart.call(this, vis());
					}
					running = true;
					if(to<0) {
						indexSet = countSet-1;
					} else if(to>countSet-1) {
						indexSet = 0;
					} else {
						indexSet = to;
					}
					dimensionShift=0;
					if(indexSet>0) {
						dimensionShift=indexSet*o.visible*dimensionSlide;
					}
					domSlides.animate(
						animCss == "left" ? { left: -(dimensionShift) } : { top: -(dimensionShift) } , o.speed, o.easing,
						function() {
							if(o.afterEnd) {
								o.afterEnd.call(this, vis());
							}
							running = false;
						}
					);
					return false;
				}
			}
			if(o.start!==0) {
				slideTo(o.start);
			}
		});
	};
	function css(el, prop) {
		return parseInt($.css(el[0], prop), 10) || 0;
	}
	function width(el) {
		//alert("testo"+el[0].offsetWidth);
		return  el[0].offsetWidth + css(el, 'marginLeft') + css(el, 'marginRight');
	}
	function height(el) {
		return el[0].offsetHeight + css(el, 'marginTop') + css(el, 'marginBottom');
	}
})(jQuery);
// User Login 
function userLogin($type) {
	if($type=="facebook") {
		//$("#user").html('<fb:name uid=loggedinuser useyou=false></fb:name>');
		var fbAPI = FB.Facebook.apiClient;
		//var emailPermission = 0;
		//FB.Connect.showPermissionDialog("email", function(x){ emailPermission=1; });
		var fbUID = FB.Facebook.apiClient.get_session().uid;
		viewer  = fbAPI.fql_query('SELECT name, first_name, last_name, profile_url, sex, birthday_date, locale, email_hashes, proxied_email FROM user WHERE uid='+fbUID,
			function(results) {
				//$("#user").html(results[0].name);
				//$("#user").html('<div id="username"><fb:name uid=loggedinuser useyou=false></fb:name></div><div id="buttonHead"><div id="buttonLeft"></div><div id="buttonCenter"><a href="#" onclick="FB.Connect.logoutAndRedirect(\'Test.php\')">Logout</a></div><div id="buttonRight"></div></div>');
				$("#loginbox").fadeOut();
				$.ajax({
					type: "POST",
					url: includePath+"ajax.php",
					data: "action=facebookuser&fbid="+fbUID+"&name="+results[0].name+"&firstname="+results[0].first_name+"&lastname="+results[0].last_name +"&profileurl="+ results[0].profile_url+"&locale="+ results[0].locale+"&sex="+results[0].sex+"&birthday="+results[0].birthday_date+"&email=",
					dataType: "html",
					success: function(returnedData) {
						//$("#user").append(returnedData);
						//alert(returnedData);
						location.reload(true); 
					}
				});
			}
  		);
		FB.XFBML.Host.parseDomTree(); 
	} else if($type=="fox") {
	} else {
	}
}
function updateUserBox() {
	//$("#user").html('<div id="username"><fb:name uid=loggedinuser useyou=false></fb:name></div><div id="buttonHead"><div id="buttonLeft"></div><div id="buttonCenter"><a href="#" onclick="FB.Connect.logoutAndRedirect(\'Test.php\')">Logout</a></div><div id="buttonRight"></div></div>');
	//FB.XFBML.Host.parseDomTree();
}
function showHero(temp3) {
		working=true;
		$("#heroes .hero:eq("+currHero+")").fadeOut(function() {
			$("#heroes .hero:eq("+temp3+")").fadeIn(function() {
				working=false;
				$(".herovideo:visible").fadeOut();
				$(".heroplay:hidden").fadeIn();
			});
		});
		$(".heronav ul .active").removeClass("active");
		$(".heronav ul li:eq("+temp3+")").addClass("active");
		if(temp3===0 || temp3==0) { temp2=parseInt(countHeroes,10)-1;  }
		else { temp2=parseInt(temp3,10)-1;  }
		$(".heroprev").attr("rel",temp2);
		if(temp3==countHeroes-1) { temp2=0; }
		else { temp2=parseInt(temp3,10)+1; }
		$(".heronext").attr("rel",temp2);
		currHero = temp3;
}
function jumpNextHero() {
	if(working===false) {
		temp = $(".heronext").attr("rel");
		showHero(temp);
	}
}
function showPreview(coords) {
	if (parseInt(coords.w, 10) > 0) {
		var rx = previewWidth / coords.w;
		var ry = previewHeight / coords.h;
		$("#x").val(coords.x);
		$("#y").val(coords.y);
		$("#w").val(coords.w);
		$("#h").val(coords.h);
		jQuery('.croppreview').css({
			width: Math.round(rx * imageWidth) + 'px',
			height: Math.round(ry * imageHeight) + 'px',
			marginLeft: '-' + Math.round(rx * coords.x) + 'px',
			marginTop: '-' + Math.round(ry * coords.y) + 'px'
		});
	}
}
function Jrefresh() {
	//$(".cropimage").load(function(){
		$(".cropimage").Jcrop({
			onChange: showPreview,
			onSelect: showPreview,
			boxWidth: 480,
			boxHeight: 480,
			aspectRatio: imageRatio,
			setSelect: [10,10,minWidth,minHeight],
			minSize: [minWidth, minHeight]
		});
	//});
	//imgEditObj = $.Jcrop(".cropbox",{	});
}
function trimString (str) {
	var	str = str.replace(/^\s\s*/, ''),
		ws = /\s/,
		i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);
}
function resizeMyView() {
    var ifrmDiv	=          window.frames['frm_rbody'].document.getElementById('rbody3MainDiv');
    var height  =          ifrmDiv.scrollHeight;
    var width   =          ifrmDiv.scrollWidth;
    if(height < 375) {
               $("#msgDiv2").height(500);
    } else {
               $("#msgDiv2").height(height + 125);
    }
    if( width > 779 ) {
       if($('#rbodyMainDiv').offsetLeft > 5) {
          $('rbodyMainDiv').css(margin-left,$('#rbodyMainDiv').offsetLeft - 5);
       }
       $("#msgDiv2").width(width + 35);
    }
}
// Page is loaded
$(document).ready(function() {
	//alert("teststart");
// Set Dynamic Variables 
	var site = $("body").attr("id");
	var imageUrl = "http://www.fic-test.com/"+site+"/PhotoContest/";
// Diagonistics
	//$("body").append("firsttext.");
// Photo Galleries
	if($("#galleryinfoDiv").length > 0 ) {
		var slideStart = $("#galleryinfoDiv .slide").index($("#galleryinfoDiv .startfrom"));
		slideStart = Math.floor(parseInt(slideStart, 10)/5);
		$(".slideshow").foxSlide({captions: true, zoomtype: "gotourl", start:slideStart, thumbs:false, btnPrev:".nobuttonprev", btnNext:".nobuttonnext"});
	}
// Splash Hero
	countHeroes = $(".hero").size();
	$("a.showhero").live("click", function(e) {
		e.preventDefault();
		if(working===false) {
			temp = $(this).attr("rel");
			showHero(temp);
		}
	});
	$("a.showvideo").live("click", function(e) {
		temp = $(this).attr("rel");
		temp2= $(this).attr("rev");
		clearInterval(intervalID);
		$("#"+temp2).fadeOut(function() {
			$("#"+temp).fadeIn();
		});
		
	});
	if(countHeroes>1) {
		intervalID = setInterval("jumpNextHero()", 5000);
	}
	$("a.playPause").live("click", function(e) {
		e.preventDefault();
		if($(this).hasClass("active")) {
			setInterval("jumpNextHero()", 5000);
			$(this).removeClass("active");
		} else {
			clearInterval(intervalID);
			$(this).addClass("active");
		}
	});
	//alert("test1");
// Splash Tabs 
	$(".tabs .tab a").live("click", function(e) {
		e.preventDefault();
		temp = $(this);	
		temp3= $(this).attr("class");
		temp2= $(this).parent();
		temp2.parent().find(".active").removeClass("active");
		temp2.addClass("active");
		if(temp3=="showtab") {
			temp = temp.attr("rel");
			$(".tabcontent:visible").fadeOut(function() {
				$(".tabcontent:eq("+temp+")").fadeIn("fast");
			});
		}
		if(temp3=="showfullschedule") {
			temp = temp.attr("rel");
			$.ajax({
				type: "POST",
				url: includePath+"ajax.php",
				data: "action=getFullSchedule&setdate="+temp,
				dataType: "html",
				success: function(returnedData) {
					//alert("budageldi");
					$("#fullschedule .programs").html(returnedData);
					countSlides = $("#fullschedule .programs .program").size();
					countSet = Math.ceil(countSlides/4);
					$("#fullschedule").find('a.getserieinfo, a.getserieshowtimes').cluetip({
						width:	550,  
						positionBy:  'fixed',
						cluezIndex:       999, 
						topOffset:        -150,       // Number of px to offset clueTip from top of invoking element. more info below [3]
						leftOffset:       -560, 
						cluetipClass:     'myschedule',		
						height:	'auto',
						arrows: false,  
						activation: 'click',
						closePosition: 'top',
						closeText: '<span>Close</span>',
						sticky: true,
						showTitle: false,
						fx: {             
							open:       'show', 
							openSpeed:  ''
						},
						onActivate:       function(e) {
							if($(".fakeLightBox").length > 0 ) {
								temp2 = $(document).height();
								$(".fakeLightBox").height(temp2);
								$(".fakeLightBox").fadeIn();
							}
							return true;
						},
						ajaxCache:        false,     
						ajaxProcess:      function(data) {
							data = $(data).not('style, meta, link, script, title');
							return data;
						},
						ajaxSettings: {   
							dataType: 'html'
						}
					});
					//alert("ajaxsonrasicount"+countSet);
				}
			});
		}
		if(temp3=="showschedule" || temp3=="changeweek") {
			if(temp3=="showschedule") {
				temp2= temp.attr("rev");
				temp = temp.attr("rel");
				temp3= $("#scheduleWeeks li.active a").attr("rel");
				if(temp3=="nextweek") { temp=temp2; }
			} else {
				//alert("geldiki");
				temp2 = temp.attr("rel");
				if(temp2=="thisweek") {
					temp= $("#scheduleDays li.active a").attr("rel");
				} else {
					temp= $("#scheduleDays li.active a").attr("rev");
				}
			}
			//alert("tarih:"+temp);
			$.ajax({
				type: "POST",
				url: includePath+"ajax.php",
				data: "action=getSchedule&setdate="+temp,
				dataType: "html",
				success: function(returnedData) {
					//alert("budageldi");
					$("#scheduleList").html(returnedData);
					countSlides = $("#scheduleList .program").size();
					countSet = Math.ceil(countSlides/4);
					//alert(countSlides);
				}
			});
		}
	});
// Splash Schedule
	if($("#splashScheduleContainer").length > 0 ) {
		var slideStart = $("#splashScheduleContainer .schedule").index($("#splashScheduleContainer .startfrom"));
		slideStart = Math.floor(parseInt(slideStart, 10)/2);
		$("#splashScheduleContainer").foxSlide({vertical: true, thumbs: false, slides: ".schedules", slide:".schedule", btnSetPrev:".up", btnSetNext:".down", slideContainer:".scheduleDiv", visible:2, start:slideStart});
	}
// Schedule 
	if($("#scheduleProgram").length > 0 ) {
		var slideStart = $("#scheduleProgram .program").index($("#scheduleProgram .startfrom"));
		slideStart = Math.floor(parseInt(slideStart, 10)/4);
		//slideStart = 0;
		//alert(slideStart);
		$("#scheduleProgram").foxSlide({vertical: true, thumbs: false, slides: ".programs", slide: ".program", btnSetPrev: ".scheduleUp", btnSetNext:".scheduleDown", slideContainer: "#scheduleDiv", visible:4, zoomtype:"gotolink", start:slideStart});
	}
	//alert("test2");
// Ajax Requests
	$("a.ajax").live("click", function(e) {
		e.preventDefault();
		temp = $(this);
		temp2 = $("form.ajax").serialize();
		$.ajax({
			type: "POST",
			url: includePath+"ajax.php",
			data: "name="+temp.attr("name")+"&rel="+temp.attr("rel")+"&rev="+temp.attr("rev")+"&"+temp2,
        	dataType: "html",
        	success: function(returnedData) {
				temp2 = $("input[name='update']").val();
				$(temp2).html(returnedData);
			}
		});
	});
// My Schedule 
	if($("#fullschedule").length > 0 ) {
		var slideStart = $("#fullschedule .program").index($("#fullschedule .currentshow"));
		slideStart = Math.floor(parseInt(slideStart, 10)/5);
		//slideStart = 0;
		//alert(slideStart);
		$(".scheduleslide").foxSlide({vertical: true, thumbs: false, slides: ".programs", slide: ".program", btnSetPrev: ".arrowup", btnSetNext:".arrowdown", slideContainer: ".schedulelist", visible:5, zoomtype: "gotourl", start:slideStart, customSlide:".schedulemodes a"});
		$("#fullschedule .programbuttons ul:hidden").show();
	}
	$(".schedulemodes a").live("click", function(e) {
		e.preventDefault();
		temp = $(this);
		temp2= temp.parent();
		temp2.parent().find(".active").removeClass("active");
		temp2.addClass("active");
	});
	$(".programbuttons a").live("mouseover",function(event) {
			$(".programbuttons a").not(this).addClass("showfront");
			$(".programbuttons").addClass("expanded");
	});
	$(".programbuttons a").live("mouseout",function(event) {
			$(".programbuttons a").not(this).removeClass("showfront");
			$(".programbuttons").removeClass("expanded");
	});
	$(".programremove a").hover(function(e) {
		$(".programremove a").addClass("expanded");
	}, function() {
		$(".programremove a").removeClass("expanded");
	});
	//alert("test3");
// Schedule Hero
	if($("#scheduleherocontainer").length > 0 ) {
		$('#scheduleheroes').nivoSlider({
			effect:'sliceDown',
			slices:15,
			animSpeed:500,
			pauseTime:60000,
			startSlide:0, //Set starting Slide (0 index)
			directionNav:true, //Next & Prev
			directionNavHide:false, //Only show on hover
			controlNav:true, //1,2,3...
			controlNavThumbs:false, //Use thumbnails for Control Nav
			pauseOnHover:true, //Stop animation while hovering
			manualAdvance:false, //Force manual transitions
			captionOpacity:0.8 //Universal caption opacity
		});
	}
	//alert("test4");
// My Schedule Tips
	if($("a.getserieinfo").length > 0 ) {
		$('a.getserieinfo, a.getserieshowtimes').cluetip({
			width:	550,  
			positionBy:  'fixed',
			cluezIndex:       999, 
			topOffset:        -150,       // Number of px to offset clueTip from top of invoking element. more info below [3]
			leftOffset:       -560, 
			cluetipClass:     'myschedule',		
			height:	'auto',
			arrows: false,  
			activation: 'click',
			closePosition: 'top',
			closeText: '<span>Close</span>',
			sticky: true,
			showTitle: false,
			fx: {             
				open:       'show', 
				openSpeed:  ''
			},
			onActivate:       function(e) {
				if($(".fakeLightBox").length > 0 ) {
								temp2 = $(document).height();
								$(".fakeLightBox").height(temp2);
								$(".fakeLightBox").fadeIn();
				}
				return true;
			},
			ajaxCache:        false,     
			ajaxProcess:      function(data) {
				data = $(data).not('style, meta, link, script, title');
				return data;
			},
			ajaxSettings: {   
				dataType: 'html'
			}
		});
	}
// Ajax & Validate 
	$("form.ajaxvalidatesubmit").validate({
	   submitHandler: function(form) {
			temp = $("form.ajaxvalidatesubmit");
			temp2 = $("input[name='showdiv']").attr("value");
			temp3 = $("input[name='hidediv']").attr("value");
			//alert("ilki:"+temp2+" ikinci:"+temp3);
			temp = temp.serialize();
			$.ajax({
				type: "POST",
				url: includePath+"ajax.php",
				data: temp,
				dataType: "html",
				success: function(returnedData) {
					$(temp2).append(returnedData);
					$(temp3).fadeOut(function() {
						//alert(temp2);
						$(temp2).fadeIn();
					});
				}
			});
	   }
	});
// Form Submit
	$("a.formsubmit").live("click", function(e) {
		e.preventDefault();
		temp = $(this).attr("rel");
		$("form[name='"+temp+"']").submit();
	});
// Change Div
	$("a.changediv").live("click", function(e) {
		e.preventDefault();
		temp = $(this);
		if(temp.attr("rev")!=="") {
			$("#"+temp.attr("rev")).fadeOut(function() {
				$("#"+temp.attr("rel")).fadeIn();
			});
		}
	});
// Ajax Form Submit
	$("form.ajaxsubmit").submit(function(e) {
		e.preventDefault();
		temp = $(this);
		temp2 = $("input[name='showdiv']").attr("value");
		temp3 = $("input[name='hidediv']").attr("value");
		//alert("ilki:"+temp2+" ikinci:"+temp3);
		temp = temp.serialize();
		$.ajax({
			type: "POST",
			url: includePath+"ajax.php",
			data: temp,
        	dataType: "html",
        	success: function(returnedData) {
				$(temp2).append(returnedData);
				$(temp3).fadeOut(function() {
					//alert(temp2);
					$(temp2).fadeIn();
				});
			}
		});
	});
// Show Div
	$("a.showdiv").live("click", function(e) {
		e.preventDefault();
		temp = $(this).attr("rel");
		$("#"+temp).fadeIn("fast");
	});
// Close Div 
	$("a.closediv").live("click", function(e) {
		e.preventDefault();
		temp = $(this).attr("rel");
		$("#"+temp).fadeOut();
	});
//  Slide Div
	$("a.slidediv").live("click", function(e) {
		e.preventDefault();
		temp = $(this);
		temp2= $(this).attr("rel");
		temp3= $(this).attr("rev");
		if($(temp2).is(":visible")) {
			$(temp2).slideUp();
			temp.removeClass("expanded");
		} else {
			$(temp2).slideDown();
			temp.addClass("expanded");
		}
	});
// Quiz
	$("a.quiznext").live("click", function(e) {
		e.preventDefault();
		var temp;
		var temp2;
		var temp3;
		temp = $(this).attr("rel"); // yeni
		temp2= $(this).attr("rev"); // eski
		temp3= $("input.answer"+temp2+":checked").val();
		if (undefined === temp3) {
			$("#displayError-"+temp2).fadeIn();
		} else {
			
			$("#"+temp2).fadeOut(function() {
				$("#"+temp).fadeIn("slow");
			});
		}
	});


// Clickable Links
	$(".clickable").live("click", function(e) {
		if( e.button == 0 ) {
			temp = $(this).find("a").attr("href");
			document.location = temp;
		}
	});
	$(".clickable").hover(function() {
			$(this).addClass("hover");
		}, function() {
			$(this).removeClass("hover");
	});
// Clickable Links Opens In New Window
	$(".newwindow").live("click", function(e) {
		if( e.button == 0 ) {
			e.preventDefault();
			temp = $(this).find("a").attr("href");
			window.open(temp,'open_window','menubar, toolbar, location, directories, status, scrollbars, resizable, dependent, width=1024, height=600, left=0, top=0');
		}
	});
	$(".newwindow").hover(function() {
			$(this).addClass("hover");
		}, function() {
			$(this).removeClass("hover");
	});
// Form Validation
	$(".validate").each(function() {
		$(this).validate();
	});
// Ajax Upload and Crop 
	if ( $("#uploadajaxbutton").length > 0 ) {
		var uploadajax = new AjaxUpload('#uploadajaxbutton', {
			action: includePath+'ajaxupload.php',
			name: 'userfile',
			responseType: "json",
			//responseType: "html",
			onSubmit : function(file, ext){
				if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){
					$(".ajaxstatus").text('Invalid file! Only: .jpg, .gif, .png').show();
					return false;
				}
				$(".ajaxstatus").text('Uploading... ').show();	
				$(".submit").attr("disabled","disabled");
			},
			onComplete : function(file, response){
				//alert(file);
				//alert(response.result);
				if(response.result==2) {
					$(".ajaxstatus").text("You have reached maximum file size.").show();	
					//alert("adawdwad");
					return false;
				} else {
					file = response.filename;
					file = file.substring(file.lastIndexOf('/')+1);
					//alert(response);
					//alert(file);
					if(response.result==1) {
						minWidth 	= $("#minwidth").val();
						minHeight 	= $("#minheight").val();
						imageWidth 	= response.width;
						imageHeight = response.height;
						if(imageWidth<minWidth) {
							$(".ajaxstatus").text("Your file's width must be minimum "+minWidth).show();
							$(".submit").removeAttr("disabled");
							return false;
						} else if(imageHeight<minHeight) {
							$(".ajaxstatus").text("Your file's height must be minimum "+minHeight).show();
							$(".submit").removeAttr("disabled");
							return false;
						} else {
							//$(".croparea").html('<div class="cropdiv"><img src="" class="cropimage" /><div class="buttonSave"><div class="buttonSaveLeft"></div><div class="buttonSaveMid"><input type="submit" value="Crop &amp; Save" /></div><div class="buttonSaveRight"></div></div></div>');
							$(".cropimage").attr("src",imageUrl+"Temp/"+file);
							$(".croppreview").attr("src",imageUrl+"Temp/"+file);
							//alert(imageUrl+"Temp/"+file);
							$('.ajaxstatus').html('File successfully uploaded.').show();
							previewWidth = $("#previewwidth").val();
							previewHeight = $("#previewheight").val();
							imageRatio = previewWidth/previewHeight;
							$(".croppre div").css({"width":previewWidth+"px", "height":previewHeight+"px"});
							$("#f").val(file);
							$(".submit").removeAttr("disabled");
							//$(".ajaxupload").slideUp();
							$(".croparea").slideDown();
							Jrefresh();
						}
					} else {
						$(".ajaxstatus").text(response.result).show();	
						//alert("adawdwad");
						return false;
					}
				}
			}		
		});
	}
	$("#ajaxavatar").submit(function(e){
		e.preventDefault();
		temp = $(this);
		temp = temp.serialize();
		$.ajax({
			type: "POST",
			url: includePath+"ajax.php",
			data: "action=ajaxavatar&"+temp,
        	dataType: "html",
        	success: function(returnedData) {
				//alert(returnedData);
				temp3 = trimString(returnedData);
				$(".croparea").slideUp();
				$(".croppreview").attr("src","http://www.fic-test.com/Users/180/"+temp3);
				$(".croppreview").attr("width","180");
				$(".croppreview").attr("height","180");
				$(".croppreview").css({"width":"180px", "height":"180px", "margin-left":"0px", "margin-top":"0px"});
				temp2 = $("#profilePictureChangeAlert").text();
				$(".ajaxstatus").text(temp2);
			}
		});
	});
// Iframe Window Resize
	if($("#rbodyMainDiv").length > 0 ) {
		$(window).resize(function() {
			resizeMyView();
		});
	}
// Window Resize Operations
	/*$(window).resize( function() {
		reWidth();
	});*/
// Diagonistics
	//$("body").append("finaltext.");
	//alert("testfinal");
});
function openCenteredWindow(url) {
    var width = 580;
    var height = 435;
    var left = parseInt((screen.availWidth/2) - (width/2), 10);
    var top = parseInt((screen.availHeight/2) - (height/2), 10);
    var windowFeatures = "width=" + width + ",height=" + height + ",status,resizable,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
    myWindow = window.open(url, "subWind", windowFeatures);
}

