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).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()", 500);
	});
	
	$j(".search_popup").hover(function() {
		search_hover = true;
	},
    // Roll Out
    function() {
		search_hover = false;
		intsearch = setInterval("hideSearch()", 500);
	});
}

function hideSearch() {
	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++;
}

/************* FINE PRETTYPHOTO ***********/

/*******************/

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);







/*

CUSTOM FORM ELEMENTS

Created by Ryan Fait
www.ryanfait.com

The only things you may need to change in this file are the following
variables: checkboxHeight, radioHeight and selectWidth (lines 24, 25, 26)

The numbers you set for checkboxHeight and radioHeight should be one quarter
of the total height of the image want to use for checkboxes and radio
buttons. Both images should contain the four stages of both inputs stacked
on top of each other in this order: unchecked, unchecked-clicked, checked,
checked-clicked.

You may need to adjust your images a bit if there is a slight vertical
movement during the different stages of the button activation.

The value of selectWidth should be the width of your select list image.

Visit http://ryanfait.com/ for more information.

*/

var checkboxHeight = "25";
var radioHeight = "25";
var selectWidth = "190";


/* No need to change anything after this */


document.write('<style type="text/css">input.styled { display: none; } select.styled { position: relative; width: ' + selectWidth + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } .disabled { opacity: 0.5; filter: alpha(opacity=50); }</style>');

var Custom = {
	init: function() {
		var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
		for(a = 0; a < inputs.length; a++) {
			if((inputs[a].type == "checkbox" || inputs[a].type == "radio") && inputs[a].className == "styled") {
				span[a] = document.createElement("span");
				span[a].className = inputs[a].type;

				if(inputs[a].checked == true) {
					if(inputs[a].type == "checkbox") {
						position = "0 -" + (checkboxHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					} else {
						position = "0 -" + (radioHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					}
				}
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = Custom.clear;
				if(!inputs[a].getAttribute("disabled")) {
					span[a].onmousedown = Custom.pushed;
					span[a].onmouseup = Custom.check;
				} else {
					span[a].className = span[a].className += " disabled";
				}
			}
		}
		inputs = document.getElementsByTagName("select");
		for(a = 0; a < inputs.length; a++) {
			if(inputs[a].className == "styled") {
				option = inputs[a].getElementsByTagName("option");
				active = option[0].childNodes[0].nodeValue;
				textnode = document.createTextNode(active);
				for(b = 0; b < option.length; b++) {
					if(option[b].selected == true) {
						textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
					}
				}
				span[a] = document.createElement("span");
				span[a].className = "select";
				span[a].id = "select" + inputs[a].name;
				span[a].appendChild(textnode);
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				if(!inputs[a].getAttribute("disabled")) {
					inputs[a].onchange = Custom.choose;
				} else {
					inputs[a].previousSibling.className = inputs[a].previousSibling.className += " disabled";
				}
			}
		}
		document.onmouseup = Custom.clear;
	},
	pushed: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight*3 + "px";
		} else if(element.checked == true && element.type == "radio") {
			this.style.backgroundPosition = "0 -" + radioHeight*3 + "px";
		} else if(element.checked != true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight + "px";
		} else {
			this.style.backgroundPosition = "0 -" + radioHeight + "px";
		}
	},
	check: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 0";
			element.checked = false;
		} else {
			if(element.type == "checkbox") {
				this.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else {
				this.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
				group = this.nextSibling.name;
				inputs = document.getElementsByTagName("input");
				for(a = 0; a < inputs.length; a++) {
					if(inputs[a].name == group && inputs[a] != this.nextSibling) {
						inputs[a].previousSibling.style.backgroundPosition = "0 0";
					}
				}
			}
			element.checked = true;
		}
	},
	clear: function() {
		inputs = document.getElementsByTagName("input");
		for(var b = 0; b < inputs.length; b++) {
			if(inputs[b].type == "checkbox" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else if(inputs[b].type == "checkbox" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			} else if(inputs[b].type == "radio" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
			} else if(inputs[b].type == "radio" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			}
		}
	},
	choose: function() {
		option = this.getElementsByTagName("option");
		for(d = 0; d < option.length; d++) {
			if(option[d].selected == true) {
				document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
			}
		}
	}
}
window.onload = Custom.init;
