﻿jQuery(function(){
  initSubSectionTabs();
  initSubPagesOverview();
  applyBorderRadius();
if ($("#thumbHolder").length != 0)
{
  galleryFunctions();
}


jQuery('#catalog_order .submit').attr('disabled', '');

  jQuery('#front_carousel').innerfade({ containerheight: '283px', speed: 'slow', timeout: 6000 });

jQuery('table.contact td:last-child').addClass("lastchild");

});
function initSubSectionTabs(){
	jQuery('dl.tabs > dt > a').click(function(){
		jQuery(this).parent().siblings().removeClass('selected').end().next('dd').andSelf().addClass('selected');
		return false;
	});
}
function applyBorderRadius(){
	if(jQuery.browser.msie){
		jQuery('.box,ul.box > li').css({position:'relative'}).append('<div class="corner box-top-left" /><div class="corner box-top-right" /><div class="corner box-bottom-left" /><div class="corner box-bottom-right" />');
	}
}
function initSubPagesOverviewIconAnimation(){
	jQuery('ul.overview > li ul li').mouseover(function(){
		jQuery(this).siblings().removeClass('focus').find('a img').fadeOut(150).end().end().andSelf().addClass('focus').find('a img').fadeIn(200);
	}).filter(":first-child").trigger('mouseover');	
}
function initSubPagesOverview(){
	//IconAnimation
	var jSubPageItems=jQuery('ul.overview > li ul li').mouseover(function(){
		jQuery(this).siblings().removeClass('focus').find('a img').fadeOut(150).end().end().andSelf().addClass('focus').find('a img').fadeIn(200);
	}).filter(":first-child").trigger('mouseover');	
	//SyncListHeight
	var jSubPageLists=jSubPageItems.closest('ul'),
	maxHeight=jSubPageLists.first().height();
	jSubPageLists.each(function(index,domEl){
		maxHeight=Math.max(maxHeight,jQuery(this).height());
	}).height(maxHeight);
}

function galleryFunctions() {
        // Gallery
if(('#thumbHolder img:first-child').length !=0)
{
var regex = /image=([^&]+)/i;
        var linkbuild = "Admin/Public/GetImage.aspx?Image=[X]&Width=685&Height=234";

        var firstLink = $('#thumbHolder img:first-child').attr("src");
        var firstAlt = $('#thumbHolder img:first-child').attr("alt");

        firstLink = firstLink.match(regex)[1];
        firstLink = linkbuild.replace("[X]", firstLink);

    $('.ImgBox').attr('src', firstLink);
    $('.ImgBox').attr('alt', firstAlt);
    $("#thumbHolder img:first-child").addClass("selected");
    $(".gallerybox-highlight p:first-child").text($('.ImgBox').attr('alt').replace("http://", ""));
}

    //Clicking on an image
    $('#thumbHolder > img').click(function () {
if(('#thumbHolder img:first-child').length !=0)
{
        $("#thumbHolder img.selected").removeClass("selected");
        $(this).addClass("selected");        

        var link = $(this).attr("src");
        var alt = $(this).attr("alt");
        
        link = link.match(regex)[1];
        link = linkbuild.replace("[X]", link);
        console.log(link);

        $('.ImgBox').attr('src', link);
        $('.ImgBox').attr('alt', alt);
    $(".gallerybox-highlight p:first-child").text($('.ImgBox').attr('alt').replace("http://", ""));
        return false; 
}

});
}
