/**
 * Created by JetBrains PhpStorm.
 * User: angelikaolsson
 * Date: 6/24/11
 * Time: 10:21 AM
 * To change this template use File | Settings | File Templates.
 */


jQuery(document).ready(function($){
    $('#block-menu-block-1 .content').hide();
    
    $('.sitemap-link').click(function() {
        $('#block-menu-block-1 .content').slideToggle('2000', 'linear', function() {

        });
        $('#block-search-form').toggle('2000', 'linear', function() {

        });
        return false;
    });

    $('#block-cc-custom-content-cc-footer .links .email').hover(function(){
        $(this).children('img').attr('src', '/sites/default/modules/cc_custom_content/img/email_Rollover.gif');
    }, function(){
        $(this).children('img').attr('src', '/sites/default/modules/cc_custom_content/img/email_Normal.gif');
    });
    $('#block-cc-custom-content-cc-footer .links .facebook').hover(function(){
        $(this).children('img').attr('src', '/sites/default/modules/cc_custom_content/img/facebook_Rollover.gif');
    }, function(){
        $(this).children('img').attr('src', '/sites/default/modules/cc_custom_content/img/facebook_normal.gif');
    });
    $('#block-cc-custom-content-cc-footer .links .twitter').hover(function(){
        $(this).children('img').attr('src', '/sites/default/modules/cc_custom_content/img/twitter_Rollover.gif');
    }, function(){
        $(this).children('img').attr('src', '/sites/default/modules/cc_custom_content/img/twitter_normal.gif');
    });

    $('table .extra').hide();
    $('table span.collapsed').click(function(){
        $(this).toggleClass('expanded');
        $(this).parent().parent().toggleClass('expanded');
        $(this).parent().parent().next().toggle();
        return false;
    });
    
    $('#shopping-cart').click(function(){
        $('#shopping-cart-items').toggle();
        //$('.view-cart').toggle();
    });
    $('.price-info-link').hover(function(){
        $(this).next('.price-info-text').toggle();
    }, function() {
        $(this).next('.price-info-text').toggle();
    });
    $('.info-popup').hover(function(){
        $(this).next('.admin-comment').toggle();
    }, function() {
        $(this).next('.admin-comment').toggle();
    });

    $('.block-menu-block li').each(function(index){
        if ($(this).children('.menu').length > 0) {
            $(this).addClass('has-children');
        }
    });

    $("a[href*=.pdf]").click(function(){
    	window.open(this.href);
	    return false;
    });

    if ($('body').hasClass('front') && $('body').hasClass('i18n-en')) {
        $('body').css('background', 'url("/sites/default/themes/cirkor/img/backgrounds/full/index_eng.jpg") no-repeat scroll 0 0 #BDCEDE');
    }

    $('.view-news .views-row').click(function(){
        $(this).children('.news-title').toggleClass('news-expanded');
        $(this).children('.trimmed').toggle();
        $(this).children('.expanded').toggle();
    });

    $('.newsletter').click(function(){
        $(this).toggleClass('active');
        $('#block-mailchimp-lists-1 .mailchimp-newsletter-wrapper').toggle();
    });

    if ($('a.pay').length == 0) {
        $('a.pay-all').hide();
    }

    // styling-fixar
    if ($('.profile').length > 0 ||
        $('#user-profile-form').length > 0) {
        $('#content .section').css('margin-left', '0');
    }

});

function flashShoppingCart(callerID, html, title) {
    if (!jQuery('#'+callerID).hasClass('added')) {

        jQuery('#shopping-cart-items ul').append(html);
        jQuery('#cart-info .course-title').text(title);
        jQuery('#cart-info').fadeIn(200).delay(2000).fadeOut(200);
        Drupal.attachBehaviors(document);
    }
    else {
        jQuery('#already-exists').fadeIn(200).delay(2000).fadeOut(200);
    }
};

