/*<![CDATA[*/

/*****************************************************************************
//-> START General Functions
*****************************************************************************/
// --> Start label2value
this.label2value = function(){
	// function
	$("label.quick").each(function(){
		obj = document.getElementById($(this).attr("for"));
		if(($(obj).attr("type") == "text") || (obj.tagName.toLowerCase() == "textarea")){
			//$(obj).addClass(inactive);
			var text = $(this).text();
			$(this).css("display","none");
			$(obj).val(text);
			$(obj).focus(function(){
				//$(this).addClass(focused);
				//$(this).removeClass(inactive);
				//$(this).removeClass(active);
				if($(this).val() == text) $(this).val("");
			});
			$(obj).blur(function(){
				//$(this).removeClass(focused);
				if($(this).val() == "") {
					$(this).val(text);
					//$(this).addClass(inactive);
				} else {
					//$(this).addClass(active);
				};
			});
		};
	});
};

/*****************************************************************************
//-> END General Functions
*****************************************************************************/

/*****************************************************************************
//-> START Window Load
*****************************************************************************/

$(document).ready(function(){

// --> Append <p> seperator
	$("div#col_a div.box div.content:not(:has(ul)), div#col_a div.box div.content div.dotted:not(:has(ul))").each(function(){
		$(this).find("p").append('<img class="p-sep" src="images/p-sep.gif" alt="" />');
	});

// --> Remove <p> seperator
	$("div#col_a div.maps-select-item").each(function(){
		$(this).find("p img.p-sep").remove();
	});

// --> Remove last <p> seperator
	$("div#col_a div.box div.content, div#col_a div.box div.content div.dotted, div#col_a div.box div.section").each(function(){
		$(this).find("p:last img.p-sep").remove();
	});

// --> Remove last {div.maps-select-item} last seperator
	$("div#col_a div.box div.content").each(function(){
		$(this).find("div.maps-select-item:last, div.dotted:last").css({"border-bottom":"0px none"});
	});

// --> Remove top border from first item
	$("div.box div.content div.section:first").css({"border-top":"0px none"});

// --> Remove last box border
	$("div#col_a div.box:last").css({"border-bottom":"0px none"});

// --> Check if there is no content in the columns add &nbsp;
	if($.trim($("div#col_a").text()) == "") {
		$("div#col_a").html("&nbsp;");
	}
	if($.trim($("div#col_b").text()) == "") {
		$("div#col_b").html("&nbsp;");
	}
	if($.trim($("div#col_c").text()) == "") {
		$("div#col_c").html("&nbsp;");
	}

// --> Image Gallery
$("#pikame").PikaChoose({autoPlay:false, IESafe:true, transition:[1]});

$("#pikame").jcarousel({

	initCallback: function(carousel)
	{
		$(carousel.list).find('img').click(function() {
				var clicked = parseInt($(this).parents('.jcarousel-item').attr('jcarouselindex'));
				var last = ($(this).parents('ul').find('li:last').index() == clicked-1) ? true : false;
				if(!last){
					clicked = (clicked-2<=0) ? 0 : clicked-2;
				}
			carousel.scroll(clicked);
		});
	}
});
$("div.pika-image").after("<div class='sep'></div>");

/*
	// the thumb scroller...
	$(".jCarouselLite").jCarouselLite({
		btnNext: ".widget .prev",
		btnPrev: ".widget .next",
		speed: 500,
		easing: "easeOutQuad",
		visible: 6
	});
	// functonality...
	$(".jCarouselLite ul li img").each(function(){
		$(this).not(".active").css({"opacity":"0.5"});
		$(this).click(function() {
			var content = $(this).parent().find("span.txt").html();

			$(".jCarouselLite ul li img").removeClass("active").css({"opacity":"0.5"});

			if(content == ""){
				$(".mid div.abstract").css({"visibility":"hidden"});
			}else{
				$(".mid div.abstract").css({"visibility":"visible"}).html(content);
			}

			$(".mid img").fadeOut().attr("src", $(this).attr("src")).fadeIn();
			$(this).addClass("active").css({"opacity":"1"});
		})
	});
*/
// --> Start Filter-Form
	$("fieldset.filter-form div").each(function(){
		var flag = false;
		$(this).find("input[type=checkbox]:first").click(function () {
			if(flag){
				$(this).parent().nextAll().find(":checkbox").attr('checked', true);
				flag = false;
			}else{
				$(this).parent().nextAll().find(":checkbox").attr('checked', false);
				flag = true;
			}
		});
		// Filter-Form Clear
		$(this).parent().find("a.sbutton-blue-clear").click(function(){
			$(this).parent("fieldset").find("input[type=checkbox]").each(function () {
				$(this).attr('checked', false);
				flag = true;
			});
			return false;
		});

	});

// --> Start Filter-Form Clear
	$("fieldset#cl-chk, fieldset#cl-chk2").each(function () {
		$(this).find("a.sbutton-clear").click(function(){
			$(this).parent("fieldset").find("input[type=checkbox]").each(function () {
				$(this).attr('checked', false);
			});
			return false;
		});
	});


	// map init
	if($.cookie('mapview') == "1"){
		$("a.mClose").parent().hide();
		$("div.dim").hide();
		$("a.mOpen").show();
	}
	// map buttons
	$("a.mClose").click(function () {
		$(this).parent().hide();
		$("div.dim").hide();
		$("a.mOpen").show();
		$.cookie('mapview',1, { expires:365, path:'/'});
	});
	$("a.mOpen").click(function () {
		$("div.information").show();
		$("div.dim").show();
		$("a.mOpen").hide();
	});

	// Submit the form
	$("a.sbutton, a.sbutton2, a.sbutton-blue").click(function () {
		$("form.parent-form").submit();
		$(this).parent().parent().submit();
		$(this).parent().submit();
	});
	$("a.sbutton-newsletter").click(function () {
		$(this).parent().submit();
	});
	$("a.sbutton-contact").click(function () {
		$(this).parent().submit();
	});

	// Submit the form via select elements
	$("select.select-form-qty").change(function () {
		optVal = $(this).val();
		$("select.select-form-qty").val(optVal);
		$("form.parent-form #inputVal").val("1");
		//console.log($("#inputVal").val());
		$("form.parent-form").submit();
	});

	// Submit the form via select elements
	$("select.select-form").change(function () {
		$("form.parent-form").submit();
	});

	// Submit the form via select elements
    $("a.copy").click(function() {
       $("span.copyme").copy();
    });

	//var conHeight = $("div.box.vid").children("img.cont").height();

// --> White Patch on item.asp
    var totalHeight = 0;
	$("div.box.vid").each(function(){
		totalHeight += $(this).height() + 10;
		//console.log(totalHeight);
		$("div.box.vid img.patch").css({"height":(totalHeight+5)});
	});

// --> Remove border from last item
	//$("#col_a .box:last").addClass("last");

// --> Print Page
	$('a.printMe').click(function() {
		window.print();
	});

/*
// --> Start Sub Menu
	$('#sub-menu ul').hide();
	$('#sub-menu ul:first').show();
	$('#sub-menu li a.lnk').click(
		function() {

			var checkElement = $(this).next();
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$('#sub-menu ul:visible').slideUp('normal',function() {
					$(this).prev().removeClass("selected");
				});
				checkElement.slideDown('normal',function() {
					$(this).prev().addClass("selected");
				});
				return false;
			}
		}
	);
*/
// --> Start Sub Menu
	if($.browser.name == "msie" && $.browser.versionX <= "8"){

		$('#sub-menu ul').hide();
		$('#sub-menu a.selected').next().show();
		$('#sub-menu li a.lnk').click(
			function() {

				var checkElement = $(this).next();
				if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
					$('#sub-menu ul:visible').css({"display":"none"}).prev().removeClass("selected"); // this line enables closing an open li
					return false;
				}
				if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
					$('#sub-menu ul:visible').css({"display":"none"}).prev().removeClass("selected");
					checkElement.css({"display":"block"}).prev().addClass("selected");
					return false;
				}
			}
		);

	}else{

		$('#sub-menu ul').hide();
		$('#sub-menu a.selected').next().show();
		$('#sub-menu li a.lnk').click(
			function() {

				var checkElement = $(this).next();
				if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
					$('#sub-menu ul:visible').slideUp('normal').prev().removeClass("selected"); // this line enables closing an open li
					return false;
				}
				if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
					$('#sub-menu ul:visible').slideUp('normal').prev().removeClass("selected");
					checkElement.slideDown('normal').prev().addClass("selected");
					return false;
				}
			}
		);

	}

// --> Start Sub Menu1
	if($.browser.name == "msie" && $.browser.versionX <= "8"){

		$('#sub-menu1 ul').hide();
		$('#sub-menu1 a.selected').next().show();
		$('#sub-menu1 li a.lnk').click(
			function() {

				var checkElement = $(this).next();
				if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
					$('#sub-menu1 ul:visible').css({"display":"none"}).prev().removeClass("selected"); // this line enables closing an open li
					return false;
				}
				if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
					$('#sub-menu1 ul:visible').css({"display":"none"}).prev().removeClass("selected");
					checkElement.css({"display":"block"}).prev().addClass("selected");
					return false;
				}
			}
		);

	}else{

		$('#sub-menu1 ul').hide();
		$('#sub-menu1 a.selected').next().show();
		$('#sub-menu1 li a.lnk').click(
			function() {

				var checkElement = $(this).next();
				if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
					$('#sub-menu1 ul:visible').slideUp('normal').prev().removeClass("selected"); // this line enables closing an open li
					return false;
				}
				if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
					$('#sub-menu1 ul:visible').slideUp('normal').prev().removeClass("selected");
					checkElement.slideDown('normal').prev().addClass("selected");
					return false;
				}
			}
		);

	}

// --> Start Collapse
	if($.browser.name == "msie" && $.browser.versionX <= "8"){

		$('.collapse ul').hide();
		//$('.collapse ul:first').show();
		$('.collapse li a.lnk').click(
			function() {

				var checkElement = $(this).next();
				if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
					$('.collapse ul:visible').css({"display":"none"}).prev().removeClass("selected"); // this line enables closing an open li
					return false;
				}
				if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
					$('.collapse ul:visible').css({"display":"none"}).prev().removeClass("selected");
					checkElement.css({"display":"block"}).prev().addClass("selected");
					return false;
				}
			}
		);

	}else{

		$('.collapse ul').hide();
		//$('.collapse ul:first').show();
		$('.collapse li a.lnk').click(
			function() {

				var checkElement = $(this).next();
				if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
					$('.collapse ul:visible').slideUp('normal').prev().removeClass("selected"); // this line enables closing an open li
					return false;
				}
				if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
					$('.collapse ul:visible').slideUp('normal').prev().removeClass("selected");
					checkElement.slideDown('normal').prev().addClass("selected");
					return false;
				}
			}
		);

	}

// --> Start Cycle
	// Add 'scrollVert' functionality for scroll boxe
	(function($) {

		$.fn.cycle.transitions.scrollVert = function($cont, $slides, opts) {
		    $cont.css('overflow','hidden');
		    opts.before.push(function(curr, next, opts, fwd) {
		        $(this).show();
		        var currH = curr.offsetHeight, nextH = next.offsetHeight;
		        opts.cssBefore = fwd ? { top: -nextH } : { top: nextH };
		        opts.animIn.top = 0;
		        opts.animOut.top = fwd ? currH : -currH;
		        $slides.not(curr).css(opts.cssBefore);
		    });
		    opts.cssFirst = { top: 0 };
		    opts.cssAfter = { display: 'none' }
		};

	})(jQuery);

	// Init scroll
	$('#scroll-speacial-offers ul').cycle({
	    fx: 'scrollVert',
		speed: 850,
		rev: true,
		timeout: 6000,
		next:   '#scroll-speacial-offers ol li.next',
	    prev:   '#scroll-speacial-offers ol li.previous'
	});

// --> Init Image cycle
	$(".image-holder ul").cycle({
		fx:     'fade',
		speed:  2500,
		timeout: 5000,
		sync:1
	});

// --> Init LightBoxes
	if($.browser.name == "msie" && $.browser.versionX <= "5"){

		// --> Init ColorBox
		$("a[rel*='pop']").colorbox({
			opacity		:	0.0
		});

		}else{

		// --> Init FancyBox
		$("a[rel*='pop']").fancybox({
			titleShow		:false,
			transitionIn	:'elastic',
			transitionOut	:'elastic',
			easingIn		:'easeOutBack',
			easingOut		:'easeInBack',
			overlayOpacity	:0.0
		});

	}

// --> START FAQ's
	$("dl.faq").find('dd').hide().end().find('dt').append('<span class="expand">+ show</span>')
		.toggle(function(){
			$(this).find('span').attr('class','collapse').html('- hide').end()
			.next('dd').slideDown()
			.prev('dt').attr('class','selected').end();
		},function(){
			$(this).find('span').attr('class','expand').html('+ show').end()
			.next('dd').slideUp()
			.prev('dt').removeAttr('class').end();
		});

// --> Start Project slider
	$('#slider').nivoSlider({
		effect:'random', //Specify sets like: 'fold,fade,sliceDown'
		slices:15,
		animSpeed:800,
		pauseTime:6000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:true, //Next & Prev
		directionNavHide:true, //Only show on hover
		controlNav:true, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
		controlNavThumbsFromRel:false, //Use image rel for thumbs
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
		keyboardNav:true, //Use left & right arrows
		pauseOnHover:true, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.8, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
	});

// --> Start Disable '#' links from being clicked
	$("a[href^='#']").click(function() {
		return false;
	});

// --> Init External Links
	$("a[rel*='external']").attr("target","_blank");

// --> Stripping a tags with: class="remove"
	$("a[class*='strip']").each(function(){
		$(this).replaceWith($(this).html());
	});

// --> Init SPAM Email links
	$("a[href^='mailto:']").each(function(){
		var mail = $(this).attr("href").replace("mailto:","");
		var replaced = mail.replace("/at/","@");
		$(this).attr("href","mailto:"+replaced);
		if($(this).text() == mail){
			$(this).text(replaced);
		}
	});

// --> Init Label2Value
	label2value();
});

/*****************************************************************************
//-> END Window Load
*****************************************************************************/

/*]]>*/

