// jQuery :focus extension http://stackoverflow.com/questions/967096/using-jquery-to-test-if-an-input-has-focus

jQuery.extend(jQuery.expr[':'], {

	focus: function(element) { 

			return element == document.activeElement; 

	}

});



var twitterlogin = 'wpbakery';

var tweets_count = 5;

var string_open_video = 'Open video player';



var slideShowSpeed = 1500;

var slideEffect = 'fade';

var slideShowTimeout = 5000;



/*****************************************************************************************/

/************************** No need to modify code after this line ***********************/

/*****************************************************************************************/





var $j = jQuery.noConflict();



function equalHeights() {

	equalHeight($j(".eq1"));

	equalHeight($j(".home .twitter_sidebar, .home .layout_brick_w680"), -10);

}





function equalHeight(group, extra) {

	if (typeof extra == "undefined") { extra = 0; }



	var tallest = 0;

	var thisHeight = 0;

	group.each(function() {

		thisHeight = 0;

		thisHeight = $j(this).outerHeight();

		if(thisHeight > tallest) {

			tallest = thisHeight;

		}

	});

	group.each(function() {

		var this_h = tallest + extra;

		$j(this).height(this_h);

		

		if ($j(this).outerHeight() > this_h) {

			this_h = tallest - parseInt($j(this).css("padding-bottom")) - parseInt($j(this).css("padding-top")) + extra;

			$j(this).height(this_h);

		}

		

		if ($j(this).outerHeight() > this_h) {

			this_h = tallest - parseInt($j(this).css("padding-bottom")) - parseInt($j(this).css("padding-top")) - parseInt($j(this).css("border-top-width")) - parseInt($j(this).css("border-bottom-width")) + extra;

			$j(this).height(this_h);

		}

	});				

}



var tabSpeed = 500;

function tabsBehaviour() {

	var tabs_count = 0;

	$j(".tabs").each(function(){

		$j(this).children().addClass("tab");

		$j(this)

		.attr("id", "tabs_"+tabs_count)

		.before('<div class="tabs_nav tabs_nav_'+tabs_count+'">')

		.cycle({

			fx: 'fade',

			timeout: 0,

			speed: tabSpeed,

			containerResize: 1,

			before:  tabsOnBefore, 

			pager:  '.tabs_nav_'+tabs_count

		});

		var tab = $j(this);

		$j(".tabs_nav_"+tabs_count+" a").each(function(){

			var currentTabIndex = $j(this).prevAll().length;

			var tabTitle = $j("#tabs_"+tabs_count+" span.tabTitle").eq(currentTabIndex).html();

			$j(this).html(tabTitle);

		});

		var tabtitle = $j(this).find("span").html();

		tabs_count++;

	});

	

	function tabsOnBefore(currSlideElement, nextSlideElement, options) {

		var tabHeight = $j(nextSlideElement).outerHeight();

		$j(nextSlideElement).parent().animate({"height": tabHeight+"px"}, tabSpeed);

	}

}



/**** Global variables which are used by the image preview plugin **/

// Thanks DigitalCavalry (http://themeforest.net/user/digitalcavalry) for the box positioning hint. I owe you a beer! ;)

var g_previewImgWidth = 0;

var g_previewImgHeight = 0;

var g_imgExtraYOffset = 0;

var g_showLoader = false;

var g_initHoverX = 0;

var g_initHoverY = 0;

var g_topPositionAdjusted = false;



var g_imgDescription = '';

function imagePreviewBehaviour() {

    $j(".imgpreview").click(function() {

		return false;

	});

	$j(".imgpreview").hover(function(e) {

        var offsetX = 0;       

        var offsetY = -10;

        var hoveredObject = this;        

        var imageSrc = $j(hoveredObject).attr("href");

  

        $j("body").append('<div id="imgPreview"><div id="imgPreviewImg"></div><div id="imgPreviewDescription"></div></div>');

        $j("body").append('<div id="imgLoader"></div>');

		

        $j("#imgLoader")

			.stop()

			.css({

				"opacity" : 0,

				"left"    : (e.pageX + 8) + "px",

			    "top"     : (e.pageY - 25) + "px"

			})

			.animate({opacity: 1}, 400);

        g_showLoader = true;

            

        $j("#imgPreview").hide();

          

		var img = new Image();

		$j(img).load(function() {

			g_previewImgWidth = img.width;

			g_previewImgHeight = img.height;

			g_imgExtraYOffset = 0;

			

			offsetX = -(g_previewImgWidth / 2);

			g_imgDescription = $j(hoveredObject).attr("title");

			if (g_imgDescription.length != 0) {

				$j(hoveredObject).removeAttr('title');

				$j("#imgPreviewDescription").html(g_imgDescription);

				$j("#imgPreview").show();

				g_imgExtraYOffset = $j("#imgPreviewDescription").outerHeight(true);

				$j("#imgPreview").hide();

			} else {

				$j("#imgPreviewDescription").remove();

			}



			g_initHoverX = e.pageX;

			g_initHoverY = e.pageY;

			var browserWidth = $j(window).width();

			var browserHeight = $j(window).height();

			var previewLeftPosition = e.pageX + offsetX;

			var previewTopPosition = e.pageY + offsetY - g_previewImgHeight - g_imgExtraYOffset;

			

			if (g_previewImgHeight > e.clientY) {

			   previewTopPosition += g_imgExtraYOffset + g_previewImgHeight - offsetY*2;

			   g_topPositionAdjusted = true;

			}

			if (previewLeftPosition < 0) {

				previewLeftPosition = 0;

			}

			if (previewLeftPosition + g_previewImgWidth > browserWidth) {

				previewLeftPosition = browserWidth - g_previewImgWidth;

			}



			$j("#imgPreviewImg").html(this);

			$j("#imgPreviewImg").css({"height": g_previewImgHeight+"px"});



			$j("#imgPreview").hide()

				.css({

					 "visibility" : "visible",

					 "height"     : "auto",

					 "width"      : g_previewImgWidth+"px",

					 "top"        : previewTopPosition + "px",

					 "left"       : previewLeftPosition + "px"

				}).show();

			$j("#imgLoader").stop().animate({opacity: 0}, 400, function(){$j(this).remove()});

			g_showLoader = false;

			

			$j("#imgPreview")

				.css({

					"margin"  : "0px",

					"padding" : "0px",

					"opacity" : "0"})

				.animate({opacity: 1}, 500);

		}).attr("src", imageSrc);



    },

    // Roll Out

    function() {

		if (g_imgDescription.length != 0) {

			var titleAtr = $j("#imgPreviewDescription").html();

			$j(this).attr({"title": titleAtr});

			g_imgDescription = '';

		}

		

        $j("#imgPreview").stop().remove(); 

        $j("#imgLoader").stop().remove();

		g_topPositionAdjusted = false;

		g_showLoader = false;

    });    

    

    $j(".imgpreview").mousemove(function(e) {

		var offsetX = -g_previewImgWidth / 2;

		var offsetY = -10;

		

		var browserWidth = $j(window).width();

		var previewLeftPosition = e.pageX + offsetX;

		var previewTopPosition = e.pageY + offsetY - g_previewImgHeight - g_imgExtraYOffset;



		if (g_previewImgHeight > e.clientY || g_topPositionAdjusted == true) {

			if (g_topPositionAdjusted == true) {

				previewTopPosition += g_imgExtraYOffset + g_previewImgHeight - (offsetY*2);

			}

		}

		if (previewLeftPosition < 0) {

			previewLeftPosition = 0;

		}

		if (previewLeftPosition + g_previewImgWidth > browserWidth) {

			previewLeftPosition = browserWidth - g_previewImgWidth;

		}



		$j("#imgPreview")

			.css({

				"top"  : previewTopPosition + "px",

				"left" : previewLeftPosition + "px"

			});



		if (g_showLoader) {

			$j("#imgLoader")

				.css({

					"left" : (e.pageX + 8) + "px",

					"top"  : (e.pageY - 24) + "px"

				});

		}

	});



}; // end of function imagePreviewBehaviour



function toggleBehaviour() {

	$j('.toggle').next('div.toggle_content').find('p:last').css({'marginBottom': 0});

	

	$j('.toggle').click(function () {

		if ($j(this).hasClass("toggle_close")) {

			$j(this).stop().removeClass("toggle_close").next('div.toggle_content').slideUp(500);

		} else {

			$j(this).stop().addClass("toggle_close").next('div.toggle_content').slideDown(500);

		}

	});

}



var g_tooltipDescription = '';

function tooltipBehaviour() {

	$j(".tooltip, .flickr_badge_image img, .social img").hover(function(e) {

        var offsetX = 0;

        var offsetY = 15;

        var hoveredObject = this;        

  

        $j("body").append('<div id="tooltipDiv"></div>');

        $j("#tooltipDiv").hide();



		g_tooltipDescription = $j(hoveredObject).attr("title");

		if (g_tooltipDescription.length != 0) {

			var hovertitle = $j(hoveredObject).attr('title');

			$j(hoveredObject).removeAttr('title');

			if ($j(hoveredObject).parent().attr("title") == hovertitle) {

				$j(hoveredObject).parent().removeAttr('title');

			}

			

			$j("#tooltipDiv").html(g_tooltipDescription);

		} else {

			return;

		}

		

		g_initHoverX = e.pageX;

		g_initHoverY = e.pageY;

		var browserWidth = $j(window).width();

		var tooltipLeft = e.pageX + offsetX;

		var tooltipTop = e.pageY + offsetY;

		var tooltipWidth = $j("#tooltipDiv").outerWidth(true);

		

		if (tooltipLeft < 0) {

			tooltipLeft = 0;

		}

		if (tooltipLeft + tooltipWidth > browserWidth) {

			tooltipLeft = browserWidth - tooltipWidth;

		}

		

		$j("#tooltipDiv").hide()

			.css({

				 "visibility" : "visible",

				 "height"     : "auto",

				 "width"      : "auto",

				 "top"        : tooltipTop + "px",

				 "left"       : tooltipLeft + "px"

			}).show();

		

		var currentTooltipWidth = $j("#tooltipDiv").outerWidth(true);

		if (currentTooltipWidth > 300) {

			$j("#tooltipDiv").css({"width" : "300px"});

		}

		

		$j("#tooltipDiv")

			.css({

				"margin"  : "0px",

				"opacity" : "0"})

			.animate({opacity: 1}, 500);

    },

    // Roll Out

    function() {

		if (g_tooltipDescription.length != 0) {

			var titleAtr = $j("#tooltipDiv").html();

			$j(this).attr({"title": titleAtr});

			g_tooltipDescription = '';

		}

		

        $j("#tooltipDiv").stop().remove(); 

		g_topPositionAdjusted = false;

    });    

    

    $j(".tooltip, .flickr_badge_image img, .social img").mousemove(function(e) {

		var offsetX = 0;

		var offsetY = 15;

		

		var browserWidth = $j(window).width();

		var tooltipLeft = e.pageX + offsetX;

		var tooltipTop = e.pageY + offsetY;

		var tooltipWidth = $j("#tooltipDiv").outerWidth(true);



		if (tooltipLeft < 0) {

			tooltipLeft = 0;

		}

		if (tooltipLeft + tooltipWidth > browserWidth) {

			tooltipLeft = browserWidth - tooltipWidth;

		}



		$j("#tooltipDiv")

			.css({

				"top"  : tooltipTop + "px",

				"left" : tooltipLeft + "px"

			});



	});

} // end of function tooltipBehaviour



function slideshowBehaviour() {

	var ss_count = 0;

	var current_ss;

	$j(".small_slideshow").each(function(){

		current_ss = $j(this);

		$j(this)

		.wrap('<div class="relative"></div>')

		.before('<div class="ss_nav ss_nav_'+ss_count+'">')

		.cycle({

			fx: slideEffect, // choose your transition type, ex: fade, scrollUp, shuffle, etc...

			pause: 1,

			speed: slideShowSpeed,

			timeout: slideShowTimeout,

			delay: -ss_count * 1000,

			before: slideshowOnBefore,

			after:slideshowOnAfter,

//			easing: slideTransitionEffect,

			pager:  '.ss_nav_'+ss_count

		})

		.find('.description').width($j(this).width() - 20);

		ss_count++;

		var simg;

		var max_h, max_w;

		max_h = max_w = 0;

		$j(this).find("img").each(function(){

			var simg = new Image();

			simg.src = $j(this).attr('src');

			simg.onload = function() {

				if (simg.height > max_h) { max_h = simg.height; }

				if (simg.width > max_w) { max_w = simg.width; }

				

				$j(current_ss).css({

					"width" : max_w,

					"height" : max_h

				});

			}

		});

	});

	

	function slideshowOnBefore(currSlideElement, nextSlideElement, options) {

		$j(nextSlideElement).find("div.description").animate({"opacity": 0}, 0);

	}

	

	function slideshowOnAfter(currSlideElement, nextSlideElement, options) {

		$j(nextSlideElement).find("div.description").animate({"opacity": 1}, 2000);

	}

} // end of function slideshowBehaviour



function slidesBehaviour() {

	var ss_count = 0;

	$j(".slides_box .slides_content").each(function(){

		var prev_btn, next_btn;

		next_btn = $j(this).parent().find('.slides_next');

		prev_btn = $j(this).parent().find('.slides_prev');

		$j(this)

		.wrap('<div class="relative"></div>')

		.cycle({

			fx: 'scrollHorz', // choose your transition type, ex: fade, scrollUp, shuffle, etc...

			pause: 1,

			speed: 800,

			timeout: 0,

			delay: -ss_count * 1000,

			next: next_btn,

			prev:prev_btn

		})

		if ($j(this).find('.small_slide').length == 1) {

			$j(this).parent().parent().find('.slides_nav').hide();

		}

		ss_count++;

	});

} // end of function slidesBehaviour



function toursBehaviour() {

	var ss_count = 0;

	$j(".small_tour .small_tour_slides").each(function(){

		var tour_paging = $j(this).parent().find('.small_tour_menu');

		$j(tour_paging).addClass('small_slides_custom_paging_'+ss_count);

		

		var prev_btn, next_btn;

		next_btn = $j(this).find('.tourNextSlide');

		prev_btn = $j(this).find('.tourPrevSlide');

		$j(this)

		.wrap('<div class="relative"></div>')

		.cycle({

			fx: 'scrollHorz', // choose your transition type, ex: fade, scrollUp, shuffle, etc...

			pause: 1,

			speed: 800,

			timeout: 0,

			before: beforeTours,

			containerResize: 0, //////

			delay: -ss_count * 1000,

			next: next_btn,

			prev:prev_btn,

			pager:  tour_paging,

			pagerAnchorBuilder: function(idx, slide) { 

				return '.small_slides_custom_paging_'+ss_count+' li:eq(' + idx + ') a'; 

			}

		})

		ss_count++;

		///

		

	});

	

	$j('.small_tour_menu li:odd').addClass('odd');

	

	$j('.small_tour_menu li a').hover(

		function () {

			//mouse hover

			if ($j(this).hasClass('activeSlide') == false) {

				$j(this).stop().animate({"paddingLeft" : "20px"}, 200);

			}

		}, 

		function () {

			//mouse out

			$j(this).stop().animate({"paddingLeft" : "15px"}, 200);

		}

	);

	

	function beforeTours(currSlideElement, nextSlideElement, options) {

		var new_h = $j(nextSlideElement).height();

		$j(nextSlideElement).parent().animate({"height" : new_h});

	}

} // end of function slidesBehaviour





function filterPortfolio() {

	$j(".portfolio_filter a").click(function() {

		var href, pressed_link;

		href = $j(this).attr('href');

		pressed_link = $j(this);

		if (href == "#all") {

			$j('.portfolio_thumbnail').addClass('p_visible').slideDown("slow");

			$j('.current').removeClass('current');

			$j(pressed_link).addClass('current');

			fixSpacing();

		} else {

			var arr_nr;

			var urlArray = href.split('=');

			if (urlArray.length > 1) {

				arr_nr = 1;

			} else {

				var urlArray = href.split('/');

				if (urlArray[urlArray.length-1] == '') {

					arr_nr = 2;

				} else {

					arr_nr = 1;

				}

			}

			$j('.current').removeClass('current');

			$j(pressed_link).addClass('current');

			$j('.p_'+urlArray[urlArray.length-arr_nr]+':hidden').slideDown("slow");

			$j('.portfolio_thumbnail').addClass('p_visible');

			$j('.portfolio_thumbnail').not('.p_'+urlArray[urlArray.length-arr_nr]).removeClass('p_visible').slideUp("fast");

			/////////

			fixSpacing();

		}

		return false;

	});

} // end of function filterPortfolio



function fixSpacing() {

	if ($j('.portfolio_thumbnail').hasClass('column_one-third')) {

		$j(".p_visible").each(function(index) {

			if ((index+1)%3 == 0) {

				$j(this).addClass("last");

			} else {

				$j(this).removeClass("last");

			}

			$j(this).removeClass("clear-both");

			

			if ((index+3)%3 == 0) {

				$j(this).addClass("clear-both");

			}

		});

	} else if ($j('.portfolio_thumbnail').hasClass('column_one-half')) {

		$j(".p_visible").each(function(index) {

			if ((index+1)%2 == 0) {

				$j(this).addClass("last");

			} else {

				$j(this).removeClass("last");

			}

			$j(this).removeClass("clear-both");

			

			if ((index+2)%2 == 0) {

				$j(this).addClass("clear-both");

			}

		});

	}

}



function menuBehaviour() {

	jQuery(".header_menu li div.submenu").css({display: "none"}); // Opera Fix

	jQuery(".header_menu li a").removeAttr('title');

	jQuery(".header_menu li").each(function() {

		var sublist = jQuery(this).find('.submenu');

		jQuery(this).hover(function() {

			jQuery(this).addClass('hover');

			

			if (sublist.length > 0) {

				jQuery(this).addClass('hover_triangle');

				

				if ($j.browser.msie == true) {

					var this_x = sublist.parent().position();

					if (this_x.left + sublist.outerWidth() > 730) {

						var new_x = 730 - sublist.outerWidth() - this_x.left;

						sublist.css({"left" : new_x});

					}

				} else if ($j.browser.safari == true) {

					var this_x = sublist.parent().position();

					if (this_x.left + sublist.outerWidth() > 690) {

						var new_x = 690 - sublist.outerWidth() - this_x.left;

						sublist.css({"left" : new_x});

					}

				} else {

					var this_x = sublist.parent().position();

					if (this_x.left + sublist.outerWidth() > 928) {

						var new_x = 928 - sublist.outerWidth() - this_x.left;

						sublist.css({"left" : new_x});

					}

				}

			}



			sublist.stop().css( {height:"auto", overflow:"hidden", display:"block", opacity: 0} )

			.animate({

				opacity: 1

			}, 400, function() {

			// Animation complete.

			});

		},

		function() {

			jQuery(this).removeClass('hover hover_triangle');

			

			sublist.stop().animate({

				opacity: 0

			}, 400, function() {

				$j(this).css( {display:"none", overflow:"hidden"} );

			// Animation complete.

			});

		});

	}); 

} // end of menuBehaviour() function



function setupSliders() {

	$j('.slider').each(function(index) {

		if ($j(this).hasClass('nivo-slider')) {

			$j(this).nivoSlider({

				effect:'sliceUpLeft', //sliceDown, sliceDownLeft, sliceUp, sliceUpLeft, sliceUpDown, sliceUpDownLeft, fold, fade, random

				animSpeed:1100,

				pauseTime:5000,

				directionNav:false,

				controlNav:true,

				keyboardNav:false

			});

			nivoHeightHack($j(this));

		} else if ($j(this).hasClass('nivo-slider-fading')) {

			$j(this).nivoSlider({

				effect:'fade',

				animSpeed:1100,

				pauseTime:5000,

				directionNav:false,

				controlNav:true,

				keyboardNav:false

			});

			nivoHeightHack($j(this));

		} else if ($j(this).hasClass('slider-roundabout')) {

			$j('.slider-roundabout ul').roundabout({

				easing: 'swing',

				minOpacity: 1 // 1 fully visible, 0 invisible 

			});

		}	

	});

} // end of setupSliders function



function nivoHeightHack(nivo) {

	var sl = nivo;

	$j(window).load(function() {

		var highest_img = getHighestElement($j(sl).find('img'));

		$j(sl).height(highest_img);

	});

}



function getHighestElement(group) {

	var tallest = 0;

	var thisHeight = 0;

	group.each(function() {

		thisHeight = 0;

		thisHeight = $j(this).outerHeight();

		if(thisHeight > tallest) {

			tallest = thisHeight;

		}

	});

	return tallest;

}



function pricingTableBehaviour() {

	$j('.pricing_table .pricing_column').each(function(index) {

		$j(this).find('p:even').not('.heading').addClass('even');

		

		$j(this).find('p:last .large_button').parent().removeClass('even').addClass('tr_button');

		

		if ($j(this).next().hasClass('pricing_column_highlight')) {

			$j(this).find('p').each(function(index) {

				$j(this).not('.tr_button').css({

					"background-image"      : "url(images/res/pricing_l_shadow.png)",

					"background-repeat"     : "repeat-y",

					"background-position"   : "top right"

				});

			});

		}

		

		if ($j(this).prev().hasClass('pricing_column_highlight')) {

			$j(this).find('p').each(function(index) {

				$j(this).not('.tr_button').css({

					"background-image"      : "url(images/res/pricing_r_shadow.png)",

					"background-repeat"     : "repeat-y",

					"background-position"   : "top left"

				});

			});

		}

		

	});

	

	$j('.pricing_table').each(function(index) {

		var pr_table_width, column_count, column_width;

		pr_table_width = $j(this).width();

		column_count = $j(this).find('.pricing_column').length;

		

		column_width = pr_table_width / column_count;

		$j(this).find('.pricing_column').width(column_width);

	});

} // end of pricingTableBehaviour()



function inputBehaviour() {

	$j("input:text, textarea").each(function(){

		$j(this).attr({"rel": $j(this).val()});

		

		$j(this)

		.focus(function () {

			if ($j(this).val() == $j(this).attr('rel') && !$j(this).hasClass("static-text")) {

				$j(this).val('');

			}

			$j(this).addClass("focus");

		})

		.blur(function () {

			if ($j(this).val() == '') {

				$j(this).val($j(this).attr('rel'));

			} else {

				$j(this).addClass("notempty");

			}

			$j(this).removeClass("focus");

		});

	});

} // end of function inputBehaviour



var search_hover = false;

var intsearch = 0;



function show_search() {

	$j(".search_link").hover(function() {

		search_hover = true;

		$j(".search_popup").fadeIn();

	},

    // Roll Out

    function() {

		search_hover = false;

		intsearch = setInterval("hideSearch()", 1000);

	});

	

	$j(".search_popup").hover(function() {

		search_hover = true;

	},

    // Roll Out

    function() {

		search_hover = false;

		intsearch = setInterval("hideSearch()", 1000);

	});

}



function hideSearch() {

	if($j(".search_popup").find("input").filter(":focus").length == 0) {

		clearInterval(intsearch);

		delete intsearch;

		if (search_hover == false) {

			$j(".search_popup").fadeOut();

		}

	}

}



//var img_to_preloade_string = 'a .post_thumbnail, .img_hover, a.prettyPhoto img, .category_thumbnail a img.th';

var img_to_preloade_string = '.main_content a .post_thumbnail, .main_content .img_hover, .main_content a.prettyPhoto img, .main_content .category_thumbnail a img.th';

function thumbnailHover() {

	if ($j.browser.msie == false) {

		$j(img_to_preloade_string).hover(

			function () {

				//mouse hover

				var this_position = $j(this).position();

				$j(this).parent().append('<span class="th_hover"></span>');

				$j(this).parent().find('.th_hover').css({

					'top'    : this_position.top,

					'left'   : this_position.left,

					'width'  : $j(this).outerWidth(),

					'height' : $j(this).outerHeight()

				}).fadeOut(0).fadeIn(400);

							

				$j(this).parent().find('.th_hover').hover(

					function () {

						//mouse hover

					}, 

					function () {

						//mouse out

						$j(this).fadeOut(400, function() { $j(this).remove(); });

					}

				);

			}, 

			function () {

				//mouse out

			}

		);

	}

}

/*** Fake loader ***/

var i = 0;

var int=0;



$j(document).ready(function() {

	$j(img_to_preloade_string).css({"opacity" : 0});

	var int = setInterval("doThis(i)",150);

});



function doThis() {

	var images = $j(img_to_preloade_string).length;

	if (i >= images) {

		clearInterval(int);

	}

	$j(img_to_preloade_string).eq(i).animate({"opacity" : 1}, 400);

	i++;

}

/*******************/



function contactFormBehaviour() {

	$j(".contactform").submit(function(){

		$j(".error").removeClass("error");

		

		var randval = Math.random();

		var hasError = false;

		var sub_form = $j(this);

		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

		

		$j(this).find("input:text, textarea").each(function(index){

			var input = $j(this);

			var val = input.val();

			if ($j(this).hasClass("required") && val == "") {

				hasError = true;

				$j(this).addClass("error");

			}

			if ($j(this).hasClass("validates_as_email") && !emailReg.test(val)) {

				hasError = true;

				$j(this).addClass("error");

			}

		});

		

		var mailpath = $j(this).attr("action");

		var str = $j(this).serialize() +"&randval="+randval;

		if (hasError == false) {

			$j(".form_answer").remove();

			$j.ajax({

				 type: "POST",

				 url: mailpath,

				 data: str,

				 success: function(response)

				 {

					if (response == "ok") {

						sub_form.before('<div class="green_message messagebox form_answer">Message has been sent!</div>');

						$j(".form_answer").hide().show("fast");

					} else if (response == "error") {

						sub_form.before('<div class="yellow_message messagebox form_answer">Unknown error please try again later.</div>');

						$j(".form_answer").hide().show("fast");

					}

				 }

			});

		} else {

			if ($j(".form_answer").length == 0) {

				sub_form.before('<div class="yellow_message messagebox form_answer">Please fill in all required fields.</div>');

				$j(".form_answer").hide().show("fast");

			} else if ($j(".form_answer").hasClass("green_message")) {

				$j(".form_answer").remove();

				sub_form.before('<div class="yellow_message messagebox form_answer">Please fill in all required fields.</div>');

				$j(".form_answer").hide().show("fast");

			}

		}

		

		return false;

	});

} //end of contactFormBehaviour function



function loadTweets() {

    $j(".twitter_sidebar .tweets").tweet({

      join_text: "auto",

      username: twitterlogin,

      avatar_size: 0,

      count: tweets_count,

      auto_join_text_default: "", 

      auto_join_text_ed: "",

      auto_join_text_ing: "",

      auto_join_text_reply: "",

      auto_join_text_url: "",

      loading_text: ""

    });

} //end of loadTweets function



function fullWidthVideoBehaviour() {

	var string_close_video;

	$j('.full_width_video_close').toggle(

		function () {

            string_close_video = $j(this).html();

            $j(this).html(string_open_video);

            $j(this).parent().find('.video_container').slideUp();

            

            $j(this).parent().animate({"padding-top": 0, "padding-bottom": 0}, 500, function() { $j(this).css({"background" : "none", "border-width" : 0}) } )

            .animate({"padding-left": 0, "padding-right": 0}, 500);

        },

		function () {

			$j(this).html(string_close_video);

			$j(this).parent().find('.video_container').delay(500).slideDown();

			

			$j(this).parent().animate({"padding-left": 40, "padding-right": 40}, 500, function() { $j(this).css({"background" : "#F8F8F8", "border-width" : 1}) } )

			.animate({"padding-top": 33, "padding-bottom": 25}, 500);

		}

	);

} //end of fullWidthVideoBehaviour function



function initJsSweetness() {

	$j("a[rel^='prettyPhoto'], a.prettyPhoto, .gallery a, #slider .prettyphoto a, a.prettyphoto").prettyPhoto({

		animationSpeed: 'normal', /* fast/slow/normal */

		padding: 15, /* padding for each side of the picture */

		opacity: 0.7, /* Value betwee 0 and 1 */

		showTitle: false, /* true/false */

		allowresize: true, /* true/false */

		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */

		theme: 'facebook', /* light_rounded / dark_rounded / light_square / dark_square */

		hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */

		modal: false, /* If set to true, only the close button will close the window */

		changepicturecallback: function(){}, /* Called everytime an item is shown/changed */

		callback: function(){} /* Called when prettyPhoto is closed */

	});

	

	//equalHeights();

	tabsBehaviour();

	imagePreviewBehaviour();

	toggleBehaviour();

	tooltipBehaviour();

	slideshowBehaviour();

	slidesBehaviour();

	toursBehaviour();

	filterPortfolio();

	menuBehaviour();

	setupSliders();

	pricingTableBehaviour();

	inputBehaviour();

	show_search();

	thumbnailHover();

	contactFormBehaviour();

	loadTweets();

	fullWidthVideoBehaviour();

	//

	$j('.main_content table tr:even').addClass('even');

}



jQuery(document).ready(function($j) {

	initJsSweetness();

	

	$j(window).load(function() {

		equalHeights();

	});

});



(function($j) {

    var userAgent = navigator.userAgent.toLowerCase();



    $j.browser = {

        version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],

        safari: /webkit/.test( userAgent ),

        opera: /opera/.test( userAgent ),

        msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),

        mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )

    };



})(jQuery);
