﻿// galleries
$(document).ready(function() {
    var index = 0;
    var page = getQueryStringValue('page');
    
    $('html').attr('xmlns:og', 'http://opengraphprotocol.org/schema/');
    $('html').attr('xmlns:fb', 'http://www.facebook.com/2008/fbml');   
   
    function getQueryStringValue(argument) {
        retVal = '';
        queryString = window.location.search.substring(1);
        values = queryString.split("&");
        for (i=0; i < values.length;i++) {
            value = values[i].split("=");
            if (value[0] == argument) {
                return value[1];
            }
        }
        return retVal;
    }
       
    $('ul.list-galerie')
        .find('a, span, img')
        .each(function() {
            $(this).css('display', 'block');
            $(this).css('overflow', 'hidden');
    });
    
    $('a.facebook').click(function(e) {
        window.open($(this).attr('href'),'sharer','toolbar=0,status=0,width=626,height=436');
	    return false;
    });
    
    $('ul.list-galerie a').click(function(e) {
        e.preventDefault();
       
        var detailWidth = $(this).children().eq(1).width();
        var detailHeight = $(this).children().eq(1).height();
        $('div.galerie-detail img:first').attr('src', $(this).attr('href')).attr('width', detailWidth).attr('height', detailHeight);
        $('ul.list-galerie a').show();
        $('ul.list-galerie span').hide().removeClass('active');
        $('div.galerie-legend div.text').hide();
        $(this).hide();
        $(this).next('span').show().addClass('active');
        
        var url = 'http://' + window.location.host + window.location.pathname + '?iid=' + $(this).attr('id');
        if (page != '')
            url += '&page=' + page;
        
        $('.fbLike').attr('href', encodeURIComponent(url));
        $('a.facebook').attr('href', 'http://www.facebook.com/sharer.php?u=' + encodeURIComponent(url));
        $('a.email').attr('href', $('div.mailtext').text().replace('##url##', encodeURIComponent(url)));
        
        $('div.galerie-detail a.back').show();
        $('div.galerie-detail a.next').show();
        
        index = $('ul.list-galerie a').index(this);
        
        if (index == 0 && (page == '1' || page == ''))
            $('div.galerie-detail a.back').hide();
        if (index < 9 && (index == $('ul.list-galerie a').length - 1))
            $('div.galerie-detail a.next').hide();
    });
    
    $('div.galerie-detail a.next').click(function(e) {
        e.preventDefault();
        if (index == $('ul.list-galerie a').length - 1)
        {
            page++;
            if (page < 2)
                page = 2;
            var url ='http://' + window.location.host + window.location.pathname + '?page=' + page; 
            window.location = url;
        }
        else
            $('ul.list-galerie .active').parent().next('li').children('a').click();
    });

    $('div.galerie-detail a.back').click(function(e) {
        e.preventDefault();
        if (index == 0)
        {
            page--;
            var url ='http://' + window.location.host + window.location.pathname + '?page=' + page + '&gb=1'; 
            window.location = url;
        }
        else
            $('ul.list-galerie .active').parent().prev('li').children('a').click();
    });

    $('div.galerie-legend a.download').click(function(e) {
        e.preventDefault();
        var url = '/clubseat/galleryimage.aspx?img=' + $('div.galerie-detail img:first').attr('src');
        window.open(url);
    });
    
    var imgId = getQueryStringValue('iid');
    var goBackward = getQueryStringValue('gb');
    if (imgId != '')
        $('ul.list-galerie a[href*=' + imgId + ']').click();
    else
    {
        if (goBackward == '1')
            $('ul.list-galerie a:last').click();
        else
            $('ul.list-galerie a:first').click();
    }    
});

$(document).ready(function(){
    
    // event gallery
    
    $(".lnk-recommendation").click(function(){
        
        var imgUrl = $("div.MyEventPreviewImage").find("img").attr("src");
        var imgGuid = $.url.init(imgUrl).param("guid");
        var allParams = $.url.init().paramAll();
        
        RecommmendImage($.url.init(imgUrl).param("guid"));
    });

    // BEGIN ClubSeat CarWorld
    
    // hover effects of car navigation
    $(".CarWorldPreview")
        .hover(function(){
            // border
            $(this).find("a.CarWorldPreviewItem")
                .each(function(){$(this).css("background-color","#bfaea5");});
            // text bg
            $(this).find("span.CarText")
                .each(function(){$(this).css("background-color","#491800");});
            // layer div
            $(this).find("span.CarHover")
                .each(function(){$(this).show().fadeTo(0,0.8);});
        },
        function(){
            // border
            $(this).find("a.CarWorldPreviewItem")
                .each(function(){$(this).css("background-color","#e18b60");});
            // text bg
            $(this).find("span.CarText")
                .each(function(){$(this).css("background-color","#d3591b");});
            // layer div
            $(this).find("span.CarHover")
                .each(function(){$(this).hide();});
        }
    );
    
    // set selected car
    $.each($(".CarWorldPreview a.Active"), function(){
        $(this).parent()
            .trigger("mouseenter")
            .unbind("mouseenter")
            .unbind("mouseleave");
    });
    
    // END ClubSeat CarWorld


    // BEGIN GOOGLE ANALYTICS

    var registrationTracker = _gat._getTracker("UA-54082-7");

    // own implementation, tracking registration process
    $("a.ga-registration, a.ga-registration-cancel, a.ga-registration-register").live("click",function(){
        var regTarget = $(this).attr("text");
        if(regTarget === "")
        {
            regTarget = $("img",$(this)).attr("alt");
        }
        var trackingLink = window.location.hostname + "/"  + $.trim(regTarget).replace(" ","-")    
        //console.log("%s", trackingLink);
        registrationTracker._trackPageview(trackingLink);
    });

    // own implementation, tracking carworld teaser
    $("a.ga-carworld-teaser").live("click",function(){
        var regTarget = $(this).attr("rel");
        var trackingLink = window.location + "/"  + regTarget;  
        //console.log("%s", trackingLink);
        registrationTracker._trackPageview(trackingLink);
    });


    // usage of o8-analytics plugin

//    // init
//    $.analyticsInit({ accountId: 'UA-54082-7' });
//    // the most reliable method is as follows
//    
//    $("a.ga-registration, a.ga-registration-cancel, a.ga-registration-register")
//        .analyticsTrackPageview(
//            {
//                label:function(element)
//                {
//                    var trackedElement = $(element).text();
//                    if(trackedElement == "")
//                    {
//                        trackedElement = $("img:first-child",$(element)).attr("alt");
//                    }
//                    //console.log("%s", window.location.hostname + "/" + $.trim(trackedElement).replace(" ","-"));
//                    return  (window.location.hostname + "/" + $.trim(trackedElement).replace(" ","-"));
//                }
//            }
//        )
//     ;

       // END GOOGLE ANALYTICS
    
});

// START LOAD AND DEFINE ADD THIS FUNCTIONALITY
$(document).ready(function() {
	//if((($.browser.msie == true) && (($.browser.version == '6.0'))) != true){
		$(".add-this-functionality-menubar").each(function(){
			addthis_config = {
				ui_language: 'de',
				ui_offset_top: 0,
				ui_offset_left: 0,
				services_compact: 'facebook, twitter, delicious, linkedin, digg, stumbleupon, reddit, more',
				services_exclude: 'print, email'
			};
			$.getScript('http://s7.addthis.com/js/250/addthis_widget.js');
		});
	//}
});
// END LOAD AND DEFINE ADD THIS FUNCTIONALITY
