/*global jQuery */


/*
 |----------------------------------------------------------------------------------------------
 | 								                       		AJAX SELECTED BY WAT
 |----------------------------------------------------------------------------------------------
*/

/*(function ($, elements, OUTER_CLICK) {
	

	 // Check if the event should be fired.
	 // @param {Object} event  The click event.
	 // @private

	function check(event) {
		for (var i = 0, l = elements.length, target = event.target, el; i < l; i++) {
			el = elements[i];
			if (el !== target && !(el.contains ? el.contains(target) : el.compareDocumentPosition ? el.compareDocumentPosition(target) & 16 : 1)) {
				$.event.trigger(OUTER_CLICK, event, el);
			}
		}
	}
	
	
	$.event.special[OUTER_CLICK] = {
		
		setup: function () {
			var i = elements.length;
			if (!i) {
				$.event.add(document, 'click', check);
			}
			if ($.inArray(this, elements) < 0) {
				elements[i] = this;
			}
		},
		
		teardown: function () {
			var i = $.inArray(this, elements);
			if (i >= 0) {
				elements.splice(i, 1);
				if (!elements.length) {
					$.event.remove(document, 'click', check);
				}
			}
		}
		
	};
	
	
	
	 // Event helper outerClick
	 // 
	 // @param  {Function} [fn]  A function to bind to the outerClick event on each of the matched elements.
	 //                          If fn is omitted the event is triggered.
	 // @return {jQuery}         Returns the jQuery object.
	 
	$.fn[OUTER_CLICK] = function (fn) {
		return fn ? this.bind(OUTER_CLICK, fn) : this.trigger(OUTER_CLICK);
	};
	
})(jQuery, [], 'outerClick');


$(function() {
	var button = $('.ajax_select_button');
	//var menu = $('.ajax_select_menu');
	var menu = button.next('div');
	
	$('ul li a', menu).each(function() {
		$(this).append('<span />');
	});
	
	button.toggle(
	
	function(e) {
		
		e.preventDefault();
		$(this).next().css({display: 'block'});
		$('.ar', this).html('&#9650;').css({top: '3px'});
		$(this).addClass('active');
		
	},
	function() {
		
		$(this).next().css({display: 'none'});
		$('.ar', this).html('&#9660;').css({top: '5px'});
		$(this).removeClass('active');
	});
	
	button.outerClick(function (event) {

		if($(this).hasClass('active')){
			$(this).click();
		}
		
	});
});*/
/*
 |----------------------------------------------------------------------------------------------
 | 								                       		POPULA HOVER EVENT BY WAT
 |----------------------------------------------------------------------------------------------
*/
/*$(document).ready(function() {
	var htmlTxt="";
	 $("#ranks ul li").each(function(e){
		 $("#ranks ul li").eq(e).hover(function(){							  
		  htmlTxt=$(this).children(".pop_link").attr("name");					  
		 //$(this).children(".readall").show();
		  $(this).children().children(".popular").html("<span class='pop_view'><p>"+htmlTxt+"</p></span>");
		  $(this).children().children(".popular").addClass("popular_b");
		  $(this).children(".vote_st,.view_st").css("z-index","3");
		},function(){ 
		   htmlTxt="";
		  //$(this).children(".readall").hide();
		  $(this).children().children(".popular").html("<span class='pop_view'>"+htmlTxt+"</span>");
		  $(this).children().children(".popular").removeClass("popular_b");
		  $(this).children(".vote_st,.view_st").css("z-index","2");
		});
	 });
});	*/
/*
 |----------------------------------------------------------------------------------------------
 | 								                       		GREY SCALE HOVER EFFECT BY JIM
 |----------------------------------------------------------------------------------------------
*/
$(document).ready(function() {
	$("ul.gallery li.offline").hover(function() { //On hover...
		var thumbOver = $(this).find("img").attr("src"); //Get image url and assign it to 'thumbOver'
		//Set a background image(thumbOver) on the &lt;a&gt; tag 
		//$(this).find("a.thumb").css({'background' : 'url(' + thumbOver + ') no-repeat center bottom'});
		//Fade the image to 0 
		$(this).find("span").stop().fadeTo('normal', 0 , function() {
			$(this).hide() //Hide the image after fade
		}); 
	} , function() { //on hover out...
		//Fade the image to 1 
		$(this).find("span").stop().fadeTo('normal', 1).show();
	});
});	




/*
 |----------------------------------------------------------------------------------------------
 | 								                       			Replace Head Tag Wiht SWF by Wat 14-01-2011
 |----------------------------------------------------------------------------------------------
*/	
function ReplaceAll(Source,stringToFind,stringToReplace){

  var temp = Source;

    var index = temp.indexOf(stringToFind);

        while(index != -1){

            temp = temp.replace(stringToFind,stringToReplace);

            index = temp.indexOf(stringToFind);

        }

        return temp;

}

function replaceTag(tagName,divName,swfUrl,varWidth,varHeight,varFontSize,varTextAlign,varTextColor){
	var varText;
	jQuery().ready(function() {
	
	jQuery(divName+" "+tagName).each(function(i){
		varText = jQuery(this).html();
		varText = ReplaceAll(varText,"&amp;", "@removeAnd@");
		varText = ReplaceAll(varText,'"', "@removeQuote@");
		varText = ReplaceAll(varText,'&quot;', "@removeQuote@");
		
			jQuery(this).replaceWith('<embed wmode="transparent" src="'+swfUrl+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+varWidth+'" height="'+varHeight+'" FlashVars="varText='+varText+'&varWidth='+varWidth+'&varHeight='+varHeight+'&varFontSize='+varFontSize+'&varTextAlign='+varTextAlign+'&varTextColor='+varTextColor+'"></embed>');
	});		
	});
}
/*
 |----------------------------------------------------------------------------------------------
 | 								                       			Validate Flash by jenghy - 07-12-2010 
 |----------------------------------------------------------------------------------------------
*/	
function embedFlashObj(Embpath,Embwidth,Embheight){
var flashCode = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+Embwidth+'" height="'+Embheight+'"><param name="movie" value="'+Embpath+'" /><param name="quality" value="high" /> <embed wmode="transparent" src="'+Embpath+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+Embwidth+'" height="'+Embheight+'"></embed></object>';
document.write(flashCode) ;
}
/*
 |----------------------------------------------------------------------------------------------
 | 								                     	Hover-Login Box by jenghy - 10-01-2011 
 |----------------------------------------------------------------------------------------------
*/
/*$(document).ready(function(){
	$("#loginbox_hover").hover(function(){
		  $(".grid_10 #popup-loginbox").slideToggle("slow");
	},function(){ 
  $(".grid_10 #popup-loginbox").slideToggle("slow")
  }); 
});*/

$(document).ready(function(){
	$("#accountbox_hover").click(function(){
		  $(".account-show #popup-accountbox").slideToggle("slow")
	});
});

$(document).ready(function(){
	$("#loginbox_hover").click(function(){
		  $(".login-show #popup-loginbox").slideToggle("slow")
	});
	$(".login_to_post").click(function(){
		  $(".login-show #popup-loginbox").slideToggle("slow");
	});
});

/*
 |----------------------------------------------------------------------------------------------
 | 								                     Toggle-Directory page by jenghy - 17-12-2010 
 |----------------------------------------------------------------------------------------------
*/$(document).ready(function(){
   $(".togglebox").hide();
   $("span.toggle").click(function(){
  	 $(this).next(".togglebox").slideToggle("slow");
  	 return true;
  });
});

/*
 |™*******************************************************************************************™*
 | jQuery comment box by jenghy 22-12-2010
 |™*******************************************************************************************™*
*/

	function Reply(s, value) {

	//$("span.reply-comment, .close").click(function(){
		
		var reply = $('#reply' + value).children("#HIDreply").val();
		
		$("#form").slideUp("slow");
			
		$("input[name='HIDreply']").val('close');
		
		$('#reply' + value).children("#HIDreply").val(reply);
		$("div.reply-form").slideUp("slow");

		if ( $('#reply' + value).children("#HIDreply").val() == 'close' ) {
			
			$('#reply' + value).children("#HIDreply").val('open');
			$(s).toggleClass("active");
			$('#reply' + value).slideToggle("slow");
		
		} else {
			$('#reply' + value).children("#HIDreply").val('close');
			$("#form").slideDown("slow");
		}
		
	//});
	
	}


/*
 |----------------------------------------------------------------------------------------------
 | 								                       			search-bar by TOR - 17-12-2010 
 |----------------------------------------------------------------------------------------------
*/

$(function(){
				
//		$("#TXTsearch").focus(function() { 
//			
//			$(this).parent().find(".fancy-panel").show();
//			$('div.arrow').removeClass('arrow-up').addClass('arrow-down');
//			$(this).parent().hover(function() {
//			}, function(){	
//				$(this).parent().find(".fancy-panel").hide();
//				$('div.arrow').removeClass('arrow-down').addClass('arrow-up');
//			});
//
//		});
		
		$('input.all-cats').click(function(){
			if ($(this).attr('checked') == false){
           	 	$('input.sub-cat').attr({disabled:false,checked:false});
       		}else{
				$('input.sub-cat').attr({disabled:true,checked:true});
			}
		});
		
		
		
/*		$('form').submit(function(){
			
			var input = $('.text-input');
			
			if(input.val() == "" || input.val() == 'SEARCH...'){
				$(this).parent().find(".fancy-panel").show();
				$('div.arrow').removeClass('arrow-up').addClass('arrow-down');
				$(this).parent().hover(function() {
				}, function(){	
					$(this).parent().find(".fancy-panel").hide();
					$('div.arrow').removeClass('arrow-down').addClass('arrow-up');
				});
				return false;
			}else{
				return true;	
			}
			
		});*/
		
	});
	
/*
 |----------------------------------------------------------------------------------------------
 | 								                       Scrollable INDEX PAGE by TOR - 17-12-2010 
 |----------------------------------------------------------------------------------------------
*/
	
$(document).ready(function() {
	/*var i = 0;
	var l = $("ul#slide li a img").length;
	var s = 884;
	var w = 221;
	var show = 4;
	var timeOut = 200;*/
	
	var $next = $("#leftBtn").hide();
	var $prev = $("#rightBtn").hide();
	
	
	/*alert($("ul#slide li").outerWidth());*/
	//alert(l/8*-400);
	//alert(l);
	
	/*$("ul#slide li").each(function(index) {
		//alert(index*4);
		var num = Math.ceil(index*l/2);
		if(num <= l){
    		$('ul#slide li').eq(num).css({clear:'both'});
		}
  	});*/

	
	/*var $next = $("#leftBtn");
	var $prev = $("#rightBtn");
	
	var set_w = w * l;
	$("ul#slide").width(set_w + "px");
	
	if(l<=show){$($next,$prev).hide();}
	$prev.hide();
	
	$next.click(function(){
		var p = i -= s;
		
		$prev.show();*/
		
		//var last = (Math.ceil(l/8-1)*s)*-1;
		//alert(last)
		
		//if(p == last){
			//$next.hide();
		//}
		/*if(p == last){
			$(this).hide()
		}*/
		//$("#btn_r").show();
		//$("ul#slide").animate({marginLeft: p + "px"},900);
	//});
	
	//$prev.click(function(){
		//$next.show();
		//var p = i += s;
		//if(p == 0){ $prev.hide(); }
		//$("#btn_l").show()
		//p == 0 ? $(this).hide(): $(this).show();
		//$("ul#slide").animate({marginLeft: p + "px"},900);
	//});
		
});

/*
 |----------------------------------------------------------------------------------------------
 | 								                       			Scrollable by TOR - 20-12-2010 
 |----------------------------------------------------------------------------------------------
*/

jQuery(document).ready(function() {
	var i = 0;
	var l = $("ul#slideAll li").length;
	var s = 884;
	var w = 221;
	var show = 4;
	var timeOut = 200;
	
	
	/*alert($("ul#slide li").outerWidth());*/
	//alert(l/8*-400);
	
	
	var $next = $("#leftBtn2");
	var $prev = $("#rightBtn2");
	
	var set_w = w * l;
	$("ul#slideAll").width(set_w + "px");
	
	if(l<=show){$($next,$prev).hide();}
	$prev.hide();
	
	$next.click(function(){
		var p = i -= s;
		
		$prev.show();
		
		var last = ((s * show)-(s))*-1;
		//alert(last);
		
		if(p == last){
			$next.hide();
		}
		
		jQuery("ul#slideAll").animate({marginLeft: p + "px"},900);
	});
	
	$prev.click(function(){
		$next.show();
		var p = i += s;
		if(p == 0){ $prev.hide(); }
		//$("#btn_l").show()
		//p == 0 ? $(this).hide(): $(this).show();
		jQuery("ul#slideAll").animate({marginLeft: p + "px"},900);
	});
		
});

/*
 |™*******************************************************************************************™*
 | jQuery mediabox by jenghy 30-09-2010
 |™*******************************************************************************************™*
*/

$(document).ready(function(){
	$("#mediabox_hover").click(function(){
		  $("#popup-mediabox").slideToggle("slow")
		  $('li.mediabox').toggleClass("on");
	});
	
	$("#m-close").click(function(){
		  $("#popup-mediabox").slideUp("slow")
		  $('li.mediabox').toggleClass("on");
	});
});


/*
 |----------------------------------------------------------------------------------------------
 | 								                       			Tab by jenghy - 07-12-2010 
 |----------------------------------------------------------------------------------------------

$(document).ready(function() {
	//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content
	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});
});	*/
/*
 |----------------------------------------------------------------------------------------------
 | 								                       			loopedslider by jenghy - 07-12-2010 
 |----------------------------------------------------------------------------------------------
*/	
$(document).ready(function(){
			$('#loopedslider').loopedSlider({
				addPagination: true,
				autoStart: 900000,// Speed Default 90000
				hoverPause: true
			});
		});


$(document).ready(function(){	
	jQuery("#menu").pk_menu();
	jQuery("#options_wrapper").pk_options_menu();

	/* GALLERIES */

	if(jQuery("#project_details").length == 0) {
		jQuery(".big_gallery").pk_gallery({
			photos: ".item",
			thumbs: ".gallery_navigation a",
			buttonNext: ".gallery_button_next",
			buttonPrev: ".gallery_button_prev",
			buttonPlayPause: ".button_play_pause",
			easing: "easeInOutQuad",
			speedIn: 400,
			speedOut: 600,
			timer:10000
		});
		jQuery(".small_gallery").pk_gallery({
			photos: ".item",
			thumbs: ".gallery_navigation a",
			buttonNext: ".gallery_button_next",
			buttonPrev: ".gallery_button_prev",
			buttonPlayPause: ".button_play_pause",
			easing: "easeInOutQuad",
			speedIn: 400,
			speedOut: 600,
			timer:10000
		});
	}
	jQuery("#project_details").pk_gallery({
		photos: ".project",
		//thumbs: "#grid div.box_one_third .small_shadow",
		thumbs: "#shop-gallery div.container_24 .grid_7 .small_shadow",
		buttonNext: "#portfolio_navigation .next",
		buttonPrev: "#portfolio_navigation .prev",
		buttonClose: ".button_close",
		autoStart: false,
		toogle: true
	});

	/* TWITTER */

/*	jQuery(".twitter_list").pk_twitter({
		user: "jdesignthailand",
		count: 3
	});*/

	/**/

	jQuery("#grid").pk_portfolio();
	jQuery("#categories_dropdown").pk_dropdown();
	jQuery("input:text, input:password, textarea").pk_input();
	jQuery("#contact_form").pk_form();
	jQuery("body").pk_improvements();
});

/*
  * JD_MENU ***
*/

(function($) {
	$.fn.pk_menu = function(options) {
		var defaults = {
			autoPosition: false,
			limitValue: "wrapper",
			easing: "easeOutQuint",
			speedIn: 400,
			speedOut: 100
		};
		
		var settings = $.extend({}, defaults, options);
		
		/**/
		
		return this.each(function () {
			var $root = $(this);
			var $mainmenu = $(">ul", this);
			var $headers = $mainmenu.find("ul").parent();
			var $limitValue = (settings.limitValue == "document") ? $(window).width() : 960;
            
			/**/
		
			$headers.each(function () {
				var $curobj = $(this);
				var $subul = $(this).find('ul:first');
				var $ul = $("ul", $curobj);
			
				$("ul ul", $root).css({"display": "none", "paddingTop": "0px"}).find("li:first").css({"marginTop": "15px"});
				$("ul ul ul", $root).find("li:first").css({"marginTop": "5px"});
			
				/**/
			
				function getProperty($li, $ul) {
					$li.dimensions = {
						w: $li.offsetWidth, 
						h: $li.offsetHeight, 
						subulw: $ul.outerWidth(), 
						subulh: $ul.outerHeight()
					}
					return $li.dimensions;
				}
			
				function showMenu ($element) {
					$element.css({visibility:'visible'}).slideDown(settings.speedIn);
				}
 
    			function hideMenu ($element, $current) {
    				$element.slideUp(settings.speedIn, function() {
    					$element.hide();
    				});
    				setTimeout(function() { 
        				$current.stop().animate({
        					borderBottomWidth: "5px"
        				}, settings.speedIn + 100, "easeInOutSine");
   				 	}, 100); 
    			}
			
				/**/
				$curobj.click(function() {
					var $targetul = $(this).find("ul:first");
					$targetul.hide();
				});
				$curobj.hoverIntent(function() {
					closeOptionsMenu();
					getProperty(this, $subul);
					
					if($(this).find("current")) {
						$(this).stop().animate({borderBottomWidth: "0px"}, 1, "easeInOutSine");
					}
					
					var $targetul = $(this).find("ul:first");
					var $offset = $(this).offset();
				
					if($curobj.parents("ul").length == 1) {
						$ul.css({visibility:'hidden'});
						this.firstLevel = true;
						$subul.css({top: 30 + "px"});
					} else {
						this.firstLevel = false;
						$subul.css({top: -5 + "px"});
					}
					
					if(this.firstLevel) {
						var menuleft = 0;
					} else {
						var menuleft = this.dimensions.w;
					}
					
					if(($offset.left + menuleft + this.dimensions.subulw) > $limitValue && !this.firstLevel) {
						menuleft = -(this.dimensions.w);
					}
				
					if(settings.autoPosition == true) {
						$targetul.css({left:menuleft + "px"});
					}
					showMenu($targetul);

				}, function() {
					var $targetul = $(this).find("ul:first");
					hideMenu($targetul, $(this));
				});
			});
		});
	};
})(jQuery);

/*
  * JD_OPTIONS_MENU ***
*/

function closeOptionsMenu() {
	jQuery("#options_wrapper div").filter(":visible").stop().slideUp(400, function() {
		jQuery("#options_wrapper").hide();
	});
}

(function($) {
	$.fn.pk_options_menu = function(options) {
		var defaults = {
			controls: "#options_menu li",
			easing: "easeOutExpo",
			speedIn: 400,
			speedOut: 100
		}
		
		var settings = $.extend({}, defaults, options);
		
		/**/
		
		return this.each(function() {
			var $root = $(this);
			var $menu = $(settings.controls);
			var $items = $("div", $root);
			var $new_item = null;
			
			$root.hide();
			
			$menu.each(function(i) {
				$(this).hoverIntent(function() {
					$new_item = $items.filter(":eq(" + i + ")");
					
					if($new_item.css("display") == "none") {
						if($root.css("display") == "none") {
							$root.show();
							$items.filter(":visible").slideUp(0);
							$new_item.slideDown(settings.speedIn);
						} else {
							$items.filter(":visible").slideUp(settings.speedOut, function() {
								$new_item.slideDown(settings.speedIn);
							});
						}
						$new_item.bind("mouseleave", function() {
							closeOptionsMenu();
						});
					}
				}, function(){});
			});
		});
	};
})(jQuery);

/*
  * JD_PORTFOLIO ***
*/

function closeProjects() {
	jQuery("#project_details .project").filter(":visible").fadeOut(400);
	jQuery('#portfolio_navigation').fadeOut(200);
	jQuery("#project_details").animate({
		"height" : "0px" 
	}, 400, "easeInOutQuad");
	jQuery('.breadcrumb').animate({"paddingTop": "70px"}, 400, "easeInOutQuad");
}

(function($) {
	$.fn.pk_portfolio = function(options) {
		var defaults = {
			easing: "easeInOutQuad",
			speedIn: 400,
			speedOut: 200
		};
		
		var settings = $.extend({}, defaults, options);
		
		/**/
		
		return this.each(function() {
			var $root = $(this);
			
			if($("body").find(".portfolio_big_gallery").length > 0) {
				$("#project_details .project").each(function(i) {
					$("#p" + (i + 1) + " .big_gallery").pk_gallery({
						photos: ".item",
						thumbs: "#gn" + (i + 1) + " a",
						buttonNext: "#gbn" + (i + 1),
						buttonPrev: "#gbp" + (i + 1),
						buttonPlayPause: "#pp" + (i + 1),
						autoStart: false,
						speedIn: 400,
						speedOut: 600
					});
				});
			}
			
			if($("body").find(".portfolio_small_gallery").length > 0) {
				$("#project_details .project").each(function(i) {
					$("#p" + (i + 1) + " .small_gallery").pk_gallery({
						photos: ".item",
						thumbs: "#gn" + (i + 1) + " a",
						buttonNext: "#gbn" + (i + 1),
						buttonPrev: "#gbp" + (i + 1),
						buttonPlayPause: "#pp" + (i + 1),
						autoStart: false,
						speedIn: 400,
						speedOut: 600
					});
				});
			}
			
			$(".box_one_third", $root).css("background-image" , "url('images/skin/preview_icon.png')");
			$(".small_shadow", $root).find("img").hover(function(){
				$(this).stop().animate({ "opacity" : 0.3 }, 400, "easeInOutQuad");
			}, function() {
				$(this).stop().animate({ "opacity" : 1 }, 400, "easeInOutQuad");
			});
		});
	};
})(jQuery);

/*
  * JD_GALLERY ***
*/

(function($) {
	$.fn.pk_gallery = function(options) {
		var defaults = {
			photos: "",
			thumbs: "",
			buttonNext: "",
			buttonPrev: "",
			buttonPlayPause: "",
			buttonClose: "",
			/**/
			autoStart: true,
			firstClick: true,
			toogle: false,
			/**/
			timer: 5000,
			easing: "",
			speedIn: 400,
			speedOut: 200
		};
		
		var settings = $.extend({}, defaults, options);
		
		/**/
		
		return this.each(function() {
			var $root = $(this);
			var $items = $(settings.photos , $root);
			var $thumbs = $(settings.thumbs);
			var $totItems = $items.length;
			var $movies = [];
			var $status = ""; 
			var $index = 0; 
			var $interval = "";
			
			/**/
			
			function slideshow(index) {
				if(index){
					var id = index;
				} else {
					var id = 0;
				}
				$interval = setInterval(
					function() {
						play(id, "next");
					}, settings.timer
				);
			}
			
			function play(index, verse) {
				var id = index;
				if(verse == "next" || verse == undefined) {
					if(id < ($thumbs.length - 1)) {
						id++;
					} else {
						id = 0;
					}
				} else {
					if(id > 0) {
						id--;
					} else {
						id = ($thumbs.length - 1);
					}
				}
				$thumbs.filter(":eq("+ id +")").trigger("click", [true]);
			}
			
			function positionNavigation(next, prev, nav, gallery) {
				var left = (gallery.width() / 2) - (nav.width() / 2);
				var top = (gallery.height() / 2) - (next.height() / 2);
				
				next.css("margin-top", top);
				prev.css("margin-top", top);
				nav.css("margin-left", left);
			}
			
			function changeThumbs($current) {
				for(i = 0; i < $thumbs.length; i++) {
					$thumbs.filter(":eq("+ i +")").removeClass("current");
				}
				$current.addClass("current");
			}
			
			if(settings.autoStart == true) {
				$status = "play";
				$(settings.buttonPlayPause + " img").attr('src', 'images/skin/button_pause.png');
			} else {
				$status = "pause";
			}
			
			if($("body").find("#project_details").length > 0) {
				$thumbs.css("cursor", "pointer");
			}
			
			/**/

			$thumbs.each(function(i) {
				$movies[i] = $items.filter(":eq(" + i + ")").find(".movie").html();
				
				$(this).click(function() {
					var $new_item = $items.filter(":eq(" + i + ")");
					var $media = $items.filter(":eq(" + i + ")").find(".movie").length;
					var $new_height = $new_item.height();
					
					this.id = i;
					$index = this.id;
					
					if($interval) {
						clearInterval($interval);
					}
					if($media == 0 && $status == "play" && $totItems > 1) {
						slideshow(this.id);
					}
					
					if($new_item.css("display") == "none") {
						if($items.filter(":visible").find(".movie")) {
							$items.find(".movie").empty();
						}
						if($media > 0) {
							$new_item.find(".movie").html($movies[this.id]);
						}
						$items.filter(":visible").fadeOut(settings.speedOut, settings.easing);
						$new_item.fadeIn(settings.speedIn, settings.easing);
						
						if($("#project_details").length > 0) {
							var tot = $new_item.find(".item").length;
							var width = (15 * tot) + 80;
							$new_item.find(".gallery_navigation").css("width", width);
							if($("body").find(".portfolio_big_gallery").length > 0) {
								positionNavigation($new_item.find(".gallery_button_next"), $new_item.find(".gallery_button_prev"), $new_item.find(".gallery_navigation"), $new_item.find(".big_gallery"));
							}
							if($("body").find(".portfolio_small_gallery").length > 0) {
								positionNavigation($new_item.find(".gallery_button_next"), $new_item.find(".gallery_button_prev"), $new_item.find(".gallery_navigation"), $new_item.find(".small_gallery"));
							}
						}
					}
					
					if(settings.toogle == true) {
						$root.show().animate({
							"height" : $new_height 
						}, settings.speedIn, settings.easing, function() {
							$('#portfolio_navigation').slideDown(settings.speedIn);
						});
						$('html:not(:animated),body:not(:animated)').animate({ scrollTop: 0 }, settings.speedIn, settings.easing);
						$('.breadcrumb').animate({ "paddingTop": "0px"}, settings.speedIn, settings.easing);
					}
					
					changeThumbs($(this));
					
					return false;
				});
			});
			
			if($totItems > 1) {
				var width = (15 * $totItems) + 80;
				$root.find(".gallery_navigation").css("width", width);
				var left = ($root.width() / 2) - ($root.find(".gallery_navigation").width() / 2);
				var top = ($root.height() / 2) - ($(settings.buttonNext).height() / 2);
				
				/* NAVIGATION */
			
				$root.find(".gallery_navigation").show().css("margin-left", left);
				
				/* BUTTON PLAY/PAUSE */
				
				$(settings.buttonPlayPause, $(this)).click(function() {
					if($status == "play") {
						$status = "pause";
						clearInterval($interval);
						$("img", $(this)).attr('src', 'images/skin/button_play.png');
					} else {
						$status = "play";
						play($index, "next");
						$("img", $(this)).attr('src', 'images/skin/button_pause.png');
					}
				});
				
				/* BUTTONS NEXT / PREV / CLOSE */
				
				$(settings.buttonNext).show().css("margin-top", top).click(function() {
					play($index, "next");
				});
				$(settings.buttonPrev).show().css("margin-top", top).click(function() {
					play($index, "prev");
				});
			} else {
				$root.find(".gallery_navigation").hide();
			}
			
			/* BUTTON CLOSE */
			
			$(settings.buttonClose, $items).click(function() {
				closeProjects();
			});
			
			/* FIRST CLICK */
			
			if(settings.firstClick) {
				setTimeout(function() { 
        			$thumbs.filter(":eq(0)").trigger("click", [true]);
   				}, 500);
			}
		});
	}
})(jQuery);

/*
  * JD_DROPDOWN ***
*/

(function($) {
	$.fn.pk_dropdown = function(options) {
		var defaults = {
			menu: ".dropdown",
			button: ".dropdown_button",
			easing: "easeOutQuad",
			speedIn: 400,
			speedOut: 400
		};
		
		var settings = $.extend({}, defaults, options);
		
		return this.each(function() {
			var $root = $(this);
			var $menu = $(settings.menu);
			var $button = $(settings.button);
			
			$menu.hide();
			
			$root.hoverIntent(function() {
				$menu.animate({
					"height": "show"
				},settings.speedIn, settings.easing);
				$button.find("img").attr("src", "images/skin/button_close_categories.png");
			}, function() {
				$menu.animate({
					"height": "hide"
				}, settings.speedIn, settings.easing);
				$button.find("img").attr("src", "images/skin/button_open_categories.png");
			});
		});
	}
})(jQuery);


/*
  * JD_INPUT ***
*/

(function($) {
	$.fn.pk_input = function() {
		return this.each(function() {
			var $root = $(this);
			if($root.attr("autoclean") != "false") {  

				var inputValue = $root.val();
				
				function reset() {
					var value = $root.val();
					if(inputValue == value) {
						$root.val("");
					}
				}
				
				function blur() {
					var value = $root.val();
					if(value == "") {
						$root.val(inputValue);
					}
				}
				
				$root.focus(function() {
					reset();
				});
				$root.blur(function() {
					blur();
				});
			}
		});
	}
})(jQuery);

/*
  * JD_FORM ***
*/

(function($) {
	$.fn.pk_form = function(options) {
		var defaults = {
			php: "contacts-sub-core.php",
			text: "Your message has been sent. Thanks ;-)",
			response: "#response",
			submit: "#submit",
			timer: 4000,
			easing: "",
			speedIn: 400,
			speedOut: 100
		};
		
		var settings = $.extend({}, defaults, options);
		
		return this.each(function () {
			var $root = $(this);
			var $response = $(settings.response);
			var $submit = $(settings.submit);
			
			/**/
			
			function showResponse($timer) {
				$submit.fadeOut(5, function() {;
					$response.css("opacity", 0);
					$response.show().stop().animate({
 						opacity: 1
 					}, settings.speedIn, settings.easing, function(){
						interval = setInterval(hideResponse, $timer);
					});
				});
			}
			
			function hideResponse() {
				clearInterval(interval);
				$response.stop().animate({
					opacity:0
				}, settings.speedIn, settings.easing, function() {
					$response.hide();
					$submit.fadeIn(400);
				});
			}

			
			/**/
		
			$root.submit(function(){
				$.ajax({
					type: "POST",
					url: settings.php,
					data: $(this).serialize(),
					beforeSend: function() {
						// blockUI plugin
						jQuery.blockUI({
							message: "<div id='divLoading'>Please wait ...</div>",
							css: { 
								border: "none", 
								padding: "15px", 
								backgroundColor: "#000000", "-webkit-border-radius": "10px", "-moz-border-radius": "10px", 
								opacity: "0.5", 
								color: "#ffffff" 
							}
						});},
					success: function(output) {
						$response.ajaxComplete(function() {
							
							var link_split = output.split("'");
							var key = link_split[1];
							var value = link_split[3];
							
							if(key == 'SUCCESS') {
								$(this).html("<p>" + settings.text + "</p>");
								showResponse(settings.timer * 2);
							} else {
								$(this).html(value);
								showResponse(settings.timer);
							}
							
							jQuery.unblockUI();
							
						});
					}
				});
				return false;
			});
		});
	}
})(jQuery);

/*
  * JD_TWITTER ***
*/

(function($) {
	$.fn.pk_twitter = function(options) {
		var defaults = {
			user: "jdesignthailand",
			count: 1
		};
	
		var settings = $.extend({}, defaults, options);
		
		String.prototype.linkify = function() {
			return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/, function(m) {
				return m.link(m);
			});
		};
		
		function get_time(time_value) {
	  		var values = time_value.split(" ");
	  		time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
	 		var parsed_date = Date.parse(time_value);
	  		var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
	  		var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
	  		delta = delta + (relative_to.getTimezoneOffset() * 60);
	  
	  		var r = '';
	  		if (delta < 60) {
				r = 'a minute ago';
	  		} else if(delta < 120) {
				r = 'couple of minutes ago';
	  		} else if(delta < (45*60)) {
				r = (parseInt(delta / 60)).toString() + ' minutes ago';
	 		} else if(delta < (90*60)) {
				r = 'an hour ago';
	  		} else if(delta < (24*60*60)) {
				r = '' + (parseInt(delta / 3600)).toString() + ' hours ago';
	  		} else if(delta < (48*60*60)) {
				r = '1 day ago';
	  		} else {
				r = (parseInt(delta / 86400)).toString() + ' days ago';
	  		}
	  
	  		return r;
		};
		
		return this.each(function () {
			var $root = $(this);
			
			$.getJSON('http://twitter.com/status/user_timeline/' + settings.user + '.json?count=' + settings.count + '&callback=?', function(data){
				$root.find("li").remove();
				$.each(data, function(index, item){
					$root.append('<li>' + item.text.linkify() + '<small>' + get_time(item.created_at) + '</small></li>');
				});
			});
		});
	}
})(jQuery);

/*
  * JD_IMPROVEMENTS ***
*/

(function($) {
	$.fn.pk_improvements = function(options) {
		var defaults = {
			easing: "easeOutQuint",
			speedIn: "fast",
			speedOut: "fast"
		};
	
		var settings = $.extend({}, defaults, options);
		
		return this.each(function () {
			var $root = $(this);
			
			/* PRETTYPHOTO --- theme: light_rounded / dark_rounded / light_square / dark_square */
			
			/*if($("body").find("a[rel^='prettyPhoto']").length > 1) {
				$("a[rel^='prettyPhoto']").prettyPhoto({
					"default_width": 820,
					"default_height": 500,
					"opacity": 0.80,
					"animationSpeed":'slow',
					"sildeshow":20,
					"theme": 'light_rounded',
					autoplay_slideshow: true
						
				});
			}*/
			
		});
	}
})(jQuery);



/*
  * END PK_CODE ***
*/

/**
* hoverIntent is similar to jQuery's built-in "hover" function except that
* instead of firing the onMouseOver event immediately, hoverIntent checks
* to see if the user's mouse has slowed down (beneath the sensitivity
* threshold) before firing the onMouseOver event.
* 
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* hoverIntent is currently available for use in all personal or commercial 
* projects under both MIT and GPL licenses. This means that you can choose 
* the license that best suits your project, and use it accordingly.
* 
* // basic usage (just like .hover) receives onMouseOver and onMouseOut functions
* $("ul li").hoverIntent( showNav , hideNav );
* 
* // advanced usage receives configuration object only
* $("ul li").hoverIntent({
*	sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)
*	interval: 100,   // number = milliseconds of polling interval
*	over: showNav,  // function = onMouseOver callback (required)
*	timeout: 0,   // number = milliseconds delay before onMouseOut function call
*	out: hideNav    // function = onMouseOut callback (required)
* });
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($) {
	$.fn.hoverIntent = function(f,g) {
		// default configuration options
		var cfg = {
			sensitivity: 7,
			interval: 100,
			timeout: 200
		};
		// override configuration options with user supplied object
		cfg = $.extend(cfg, g ? { over: f, out: g } : f );

		// instantiate variables
		// cX, cY = current X and Y position of mouse, updated by mousemove event
		// pX, pY = previous X and Y position of mouse, set by mouseover and polling interval
		var cX, cY, pX, pY;

		// A private function for getting mouse position
		var track = function(ev) {
			cX = ev.pageX;
			cY = ev.pageY;
		};

		// A private function for comparing current and previous mouse position
		var compare = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			// compare mouse positions to see if they've crossed the threshold
			if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
				$(ob).unbind("mousemove",track);
				// set hoverIntent state to true (so mouseOut can be called)
				ob.hoverIntent_s = 1;
				return cfg.over.apply(ob,[ev]);
			} else {
				// set previous coordinates for next time
				pX = cX; pY = cY;
				// use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
				ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval );
			}
		};

		// A private function for delaying the mouseOut function
		var delay = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			ob.hoverIntent_s = 0;
			return cfg.out.apply(ob,[ev]);
		};

		// A private function for handling mouse 'hovering'
		var handleHover = function(e) {
			// next three lines copied from jQuery.hover, ignore children onMouseOver/onMouseOut
			var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
			while ( p && p != this ) { try { p = p.parentNode; } catch(e) { p = this; } }
			if ( p == this ) { return false; }

			// copy objects to be passed into t (required for event object to be passed in IE)
			var ev = jQuery.extend({},e);
			var ob = this;

			// cancel hoverIntent timer if it exists
			if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }

			// else e.type == "onmouseover"
			if (e.type == "mouseover") {
				// set "previous" X and Y position based on initial entry point
				pX = ev.pageX; pY = ev.pageY;
				// update "current" X and Y position based on mousemove
				$(ob).bind("mousemove",track);
				// start polling interval (self-calling timeout) to compare mouse coordinates over time
				if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}

			// else e.type == "onmouseout"
			} else {
				// unbind expensive mousemove event
				$(ob).unbind("mousemove",track);
				// if hoverIntent state is true, then call the mouseOut function after the specified delay
				if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
			}
		};

		// bind the function to the two event listeners
		return this.mouseover(handleHover).mouseout(handleHover);
	};
})(jQuery);


/******************************************************************************************™*
 | 					 								TOOLTIPS : CREATE DATE 01082011 - BY JIM
™*******************************************************************************************/
(function($) {

	$.fn.easyTooltip = function(options){
	  
		// default configuration properties
		var defaults = {	
			xOffset: -10,//10		
			yOffset: 30,//25
			tooltipId: "easyTooltip",
			clickRemove: false,
			content: "",
			useElement: ""
		}; 
			
		var options = $.extend(defaults, options);  
		var content;
				
		this.each(function() {  				
			var title = $(this).attr("title");				
			$(this).hover(function(e){											 							   
				content = (options.content != "") ? options.content : title;
				content = (options.useElement != "") ? $("#" + options.useElement).html() : content;
				$(this).attr("title","");									  				
				if (content != "" && content != undefined){			
					$("body").append("<div id='"+ options.tooltipId +"'>"+ content +"</div>");		
					$("#" + options.tooltipId)
						.css("position","absolute")
						.css("top",(e.pageY - options.yOffset) + "px")
						.css("left",(e.pageX + options.xOffset) + "px")						
						.css("display","none")
						.fadeIn("fast")
				}
			},
			function(){	
				$("#" + options.tooltipId).remove();
				$(this).attr("title",title);
			});	
			$(this).mousemove(function(e){
				$("#" + options.tooltipId)
					.css("top",(e.pageY - options.yOffset) + "px")
					.css("left",(e.pageX + options.xOffset) + "px")					
			});	
			if(options.clickRemove){
				$(this).mousedown(function(e){
					$("#" + options.tooltipId).remove();
					$(this).attr("title",title);
				});				
			}
		});
	  
	};

})(jQuery);


$(document).ready(function(){
	$(".tooltip").easyTooltip();
});
/******************************************************************************************™*
 | 					 CLOSE NOTIFICATION MESSAGES WHEN CLICKED : CREATE DATE 01082011 - BY JIM
™*******************************************************************************************/
$(document).ready(function(){
	// CLOSE NOTIFICATION MESSAGES WHEN CLICKED
	$(".close").click(
		function () {
			$(this).fadeTo(400, 0, function () { // Links with the class "close" will close parent
			$(this).slideUp(400);
		});
		return false;
		}
	);
});
/******************************************************************************************™*
 | 									    SIMPLE OPEN/CLOSE DIV : CREATE DATE 01082011 - BY JIM
™*******************************************************************************************/
$(document).ready(function() {
    var button = $('#ClickOpen');//ClickOpen
    var box = $('#DivOpen');//Div Open
    var form = $('#DivArea');//Area Div Enable
    button.removeAttr('href');
    button.mouseup(function(login) {
        box.toggle();
        button.toggleClass('active');
    });
    form.mouseup(function() { 
        return false;
    });
    $(this).mouseup(function(login) {
        if(!($(login.target).parent('#ClickOpen').length > 0)) {
            button.removeClass('active');
            box.hide();
        }
    });
});

$(document).ready(function() {
    var button = $('#OpenSearch');//ClickOpen
    var box = $('#DivSearch');//Div Open
    var form = $('#AreaSearch');//Area Div Enable
    button.removeAttr('href');
    button.mouseup(function(login) {
        box.toggle();
        button.toggleClass('active');
    });
    form.mouseup(function() { 
        return false;
    });
    $(this).mouseup(function(login) {
        if(!($(login.target).parent('#OpenSearch').length > 0)) {
            button.removeClass('active');
            box.hide();
        }
    });
});

/*$(document).ready(function() {
    var button = $('#loginButton');
    var box = $('#loginBox');
    var form = $('#loginForm');
    button.removeAttr('href');
    button.mouseup(function(login) {
        box.toggle();
        button.toggleClass('active');
    });
    form.mouseup(function() { 
        return false;
    });
    $(this).mouseup(function(login) {
        if(!($(login.target).parent('#loginButton').length > 0)) {
            button.removeClass('active');
            box.hide();
        }
    });
});*/
