// Created by ipbforumskins.com

var $i = jQuery.noConflict();

jQuery(document).ready(function($){

	$i('a[href=#top], a[href=#ipboard_body]').click(function(){
		$i('html, body').animate({scrollTop:0}, 400);
        return false;
	});
	
	$i(".forum_name").hover(function() {
		$i(this).next(".forum_desc_pos").children(".forum_desc_con").stop()
		.animate({left: "0", opacity:1}, "fast")
		.css("display","block")
	}, function() {
		$i(this).next(".forum_desc_pos").children(".forum_desc_con").stop()
		.animate({left: "10", opacity: 0}, "fast", function(){
			$i(this).hide();
		})
	});
	
	$i('#topicViewBasic').click(function(){
		$i(this).addClass("active");
		$i('#topicViewRegular').removeClass("active");
		$i("#customize_topic").addClass("basicTopicView");
		$.cookie('ctv','basic',{ expires: 365, path: '/'});
		return false;
	});
	
	$i('#topicViewRegular').click(function(){
		$i(this).addClass("active");
		$i('#topicViewBasic').removeClass("active");
		$i("#customize_topic").removeClass("basicTopicView");
		$.cookie('ctv',null,{ expires: -1, path: '/'});
		return false;
	});
	
	if ( ($.cookie('ctv') != null))	{
		$i("#customize_topic").addClass("basicTopicView");
		$i("#topicViewBasic").addClass("active");
	}
	else{
		$i("#topicViewRegular").addClass("active");
	}
	
	$i("#toggleThemeEditor").click(function(){
		$i("#themeEditor").slideToggle();
		$i(this).toggleClass("active");
	})
	
	var customMainElements = "body.cpe, .cpe #header, .cpe #logo, .cpe #secondary_navigation, .cpe #forum_navigation, .cpe #footer, .cpe #primary_extra_menucontent, .cpe #more_apps_menucontent, .cpe .submenu_container"
	var customMainText = ".cpe #secondary_navigation a, .cpe #secondary_navigation, .cpe #forum_navigation a, .cpe #forum_navigation"
	var customElements = ".cpe .topic_buttons li a, .cpe #index_navigation, .cpe .pagination b, .cpe .mini_pagination a, .cpe #vnc_filter_popup_close, .cpe .bar, .cpe .ipsSideBlock h3, .cpe .general_box h3, .cpe .statistics_head, .cpe .block_title, .cpe ul.post_controls, .cpe ul.post_controls li.multiquote.selected a, .cpe #board_stats .value, .cpe .post_block h3, .block_topic h3.title, .block_topic_no_r, .forumline th.block_topic_no_r";
	var customText = "a, .cpe .ipsSideBlock h3, .cpe .ipsSideBlock h3 a, .cpe #index_navigation a, .cpe .general_box h3, .cpe .general_box h3 a, .cpe .bar, .cpe .bar a, .cpe .statistics_head, .cpe .statistics_head a, .cpe .poll h3 .desc, .cpe #board_stats .value";
	var customPattern = ".cpe #logo, .cpe #header, .cpe .block_title, .cpe .post_block h3, .block_topic h3.title, .cpe #footer, .block_topic_no_r, .forumline th.block_topic_no_r"
	
	$("#themeEditor #editorPrimary span").click(function(){
		var mainColour = $(this).attr("data-main");
		$("#stylePrimary").replaceWith('<style id="stylePrimary" type="text/css">' + customMainElements + '{ background-color: #' + mainColour + '}' + customMainText + '{ color: #' + mainColour + '} </style>');
		$.cookie('shiftColour',mainColour,{ expires: 365, path: '/'});
	});
	
	$("#themeEditor #editorSecondary span").click(function(){
		var secondaryColour = $(this).attr("data-secondary");
		$("#styleSecondary").replaceWith('<style id="styleSecondary" type="text/css">' + customElements + '{ background-color: #' + secondaryColour + '}' + customText + '{ color: #' + secondaryColour + '} </style>');
		$.cookie('shiftSecondaryColour',secondaryColour,{ expires: 365, path: '/'});
	});
	
	$("#themeEditor #editorPattern span").click(function(){
		var Pattern = $(this).attr("data-pattern");
		$("#stylePattern").replaceWith('<style id="stylePattern" type="text/css">' + customPattern + '{ background-image: ' + Pattern + '} </style>');
		$.cookie('shiftPattern',Pattern,{ expires: 365, path: '/'});
	});
	
	if ( ($.cookie('shiftColour') != null))	{
		$("#stylePrimary").replaceWith('<style id="stylePrimary" type="text/css">' + customMainElements + '{ background-color: #' + $.cookie('shiftColour') + '}' + customMainText + '{ color: #' + $.cookie('shiftColour') + '} </style>');
	}
	else{
		$("#stylePrimary").replaceWith('<style id="stylePrimary" type="text/css">' + customMainElements + '{ background-color: #55728b }' + customMainText + '{ color: #55728b } </style>');
	}
	
	if ( ($.cookie('shiftSecondaryColour') != null))	{
		$("#styleSecondary").replaceWith('<style id="styleSecondary" type="text/css">' + customElements + '{ background-color: #' + $.cookie('shiftSecondaryColour') + '}' + customText + '{ color: #' + $.cookie('shiftSecondaryColour') + '} </style>');
	}
	else{
		$("#styleSecondary").replaceWith('<style id="styleSecondary" type="text/css">' + customElements + '{ background-color: #55728b }' + customText + '{ color: #55728b } </style>');
	}
	
	if ( ($.cookie('shiftPattern') != null))	{
		$("#stylePattern").replaceWith('<style id="stylePattern" type="text/css">' + customPattern + '{ background-image: ' + $.cookie('shiftPattern') + '} </style>');
	}
	else{
		$("#stylePattern").replaceWith('<style id="stylePattern" type="text/css">' + customPattern + '{ background-image: url(images/pattern/10.png) } </style>');
	}
	
	
	$("#themeTabs #themeBoxesPrimary").addClass("active");
	$("#editorSecondary").hide();
	$("#editorPattern").hide();
	
	$("#themeBoxesPrimary").click(function(){
		$("#themeBoxesSecondary").removeClass();
		$("#themeBoxesPattern").removeClass();
		$("#editorSecondary").hide();
		$("#editorPattern").hide();
		$("#editorPrimary").show();
		$(this).addClass("active");
	});
	
	$("#themeBoxesSecondary").click(function(){
		$("#themeBoxesPrimary").removeClass();
		$("#themeBoxesPattern").removeClass();
		$("#editorPrimary").hide();
		$("#editorPattern").hide();
		$("#editorSecondary").show();
		$(this).addClass("active");
	});
	
	$("#themeBoxesPattern").click(function(){
		$("#themeBoxesPrimary").removeClass();
		$("#themeBoxesSecondary").removeClass();
		$("#editorPrimary").hide();
		$("#editorSecondary").hide();
		$("#editorPattern").show();
		$(this).addClass("active");
	});

});